zoukankan      html  css  js  c++  java
  • Spring对jdbc的支持学习笔记

    1. 非加连预执释方式

    2. dataSource对jdbc的支持

        DataSource对象

      ====》JdbcTemplate jdbcTemplate

      ====》String sql = "INSERT INTO product (product_name,sale_price) VALUES (?,?)";

     ====》this.jdbcTemplate.update(sql,product.getProductName(),product.getSalePrice());

    3. 一般的连接池使用:
         Connection connection = basicDataSource.getConnection() ;

          String sql="INSERT INTO product (product_name,sale_price) VALUES (?,?)";
          PreparedStatement preparedStatement = connection.prepareStatement(sql);
    preparedStatement.setString(1,product.getProductName());
    preparedStatement.setInt(2,product.getSalePrice());
    preparedStatement.executeUpdate();
    preparedStatement.close();
    4. 原始的jdbc:

    // 加
            try {
    Class.forName("com.mysql.jdbc.Driver") ;
    // 连
    Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/station_demo", "root", "root");
    // 译
    Statement statement = connection.createStatement();
    // 执
    // String sql = "INSERT INTO product (product_name, sale_price) VALUES ('小来手机', 555)" ;
    String sql = "INSERT INTO product (product_name, sale_price) VALUES ('" + productName + "'," + salePrice + ")" ;
    statement.executeUpdate(sql) ;
    // 释
    statement.close();
    connection.close();
    逆天改命!我命由我不由天!
  • 相关阅读:
    Linux系统设置中文
    跟着小白学Linux基础命令系列
    Linux小白基础练习题
    htop命令超级好玩用法
    sed命令用法
    Linux三剑客grep命令的使用技巧
    Linux忘记密码如何修改密码
    决心书
    Linux无法上网,ping不通百度的解决方法
    AE 创建shp图层
  • 原文地址:https://www.cnblogs.com/huhewei/p/13890081.html
Copyright © 2011-2022 走看看