• Jdbc批处理一点异同


    同样的代码:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    public class TestBatch {
      public static void main(String[] args) throws SQLException, ClassNotFoundException {
        //Class.forName("oracle.jdbc.driver.OracleDriver");
        //Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","guojje","guojje");
           
         Class.forName("com.mysql.jdbc.Driver");
         Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","");
         String sql = "insert into book (kind, name) values (?,?)";
         PreparedStatement pstmt = conn.prepareStatement(sql);
         pstmt.setString(1"java");
         pstmt.setString(2"jjjj");
         pstmt.addBatch();   
         pstmt.setString(1"ccc");
         pstmt.setString(2"dddd");
         pstmt.addBatch();   
         //添加一次静态SQL
         pstmt.addBatch("update book set kind = 'JAVA' where kind='java'");
         //批量执行预定义SQL
         pstmt.executeBatch(); 
    }
    }

    MySQL是通过,对于Oracle则会报不支持特性, 原因在于addBatch动态sql之后, 

    不能再addBatch静态sql. 已此记录。



    本文转自 anranran 51CTO博客,原文链接:http://blog.51cto.com/guojuanjun/1652085

  • 相关阅读:
    mybatis的缓存机制
    mybatis动态SQL
    mybatis关联集合List&分布查询传递多列值
    winrt获取文件MD5码
    在wpf中使用winrt的Toast弹框效果
    winrt控件
    WdatePicker组件不显示
    Thread.Sleep in WinRT
    google 语音api
    UTF8编码转换(C#)
  • 原文地址:https://www.cnblogs.com/twodog/p/12138508.html
Copyright © 2020-2023  润新知