zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    【题解】【模板】矩阵级数
    【题解】P2048 [NOI2010]超级钢琴
    【题解】[APIO2009]会议中心
    【题解】[P4178 Tree]
    【题解】扑克牌游戏
    【题解】quake
    【题解】cycle
    从不浪费——分治总结
    【题解】Painting Fence
    【题解】[CJOI2019Chebnear]
  • 原文地址:https://www.cnblogs.com/twodog/p/12138505.html
Copyright © 2011-2022 走看看