加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java JDBC-批处理Batch-事务

发布时间:2020-12-15 07:26:27 所属栏目:Java 来源:网络整理
导读: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"); //
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(); } } } }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读