Jdbc批处理一点异同
同样的代码:
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. 已此记录。
本文出自 “天下无贼” 博客,请务必保留此出处http://guojuanjun.blog.51cto.com/277646/1652085
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。