首页 > 数据库技术 > 详细

java JDBC-批处理Batch-事务

时间:2019-10-09 22:57:01      阅读:99      评论:0      收藏:0      [点我收藏+]
public class Demo5 { public static void main(String[] args) { Statement stmt=null; Connection conn=null; try { Class.forName("com.mysql.jdbc.Driver"); conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","dyl123"); //设为手动提交 conn.setAutoCommit(false); stmt=conn.createStatement(); for(int i=0;i<20000;i++) { stmt.addBatch("insert into t_user(username,pwd,regTime) values(‘米"+i+"‘,555,now())"); } stmt.executeBatch(); conn.commit(); //提交事务 } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); }finally { try { stmt.close(); } catch (SQLException e) { e.printStackTrace(); } try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } }

java JDBC-批处理Batch-事务

原文:https://blog.51cto.com/14437184/2440941

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!