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();
    逆天改命!我命由我不由天!
  • 相关阅读:
    get请求乱码情况
    write()和prinln()的区别?
    校验码实现
    下载图片代码并且解析乱码
    servlet下根据相对路径找资源
    url-pattern配置
    获取网站资源 getResourceAsStream
    Servlet线程安全性
    http1.1 协议响应方面参数
    HTTP1.1协议请求方面参数
  • 原文地址:https://www.cnblogs.com/huhewei/p/13890081.html
Copyright © 2011-2022 走看看