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

  • 相关阅读:
    cocos2d-x CSV文件读取 (Excel生成csv文件)
    cocos2d-x 中 xml 文件读取
    String 类的实现
    json 文件解析与应用
    设计模式 之 《简单工厂模式》
    C++ 0X 新特性实例(比较常用的) (转)
    CCSpriteBatchNode CCSpriteFrameCache
    LongAdder
    ConcurrentHashMap源码
    HashMap源码
  • 原文地址:https://www.cnblogs.com/twodog/p/12138508.html
Copyright © 2011-2022 走看看