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();