Java入门学习addBatch()用法

1.建立链接

Connection connection =getConnection();

2.不自动 Commit

connection.setAutoCommit(false);


3.预编译SQL语句,只编译一回哦,效率高啊

PreparedStatement statement = connection.prepareStatement("INSERT INTO TABLEX VALUES(?, ?)");
//记录1
statement.setInt(1, 1);
statement.setString(2, "Cujo");
statement.addBatch();
//记录2
statement.setInt(1, 2);
statement.setString(2, "Fred");
statement.addBatch();
//记录3
statement.setInt(1, 3);
statement.setString(2, "Mark");
statement.addBatch();
//批量执行上面3条语句.
int [] counts = statement.executeBatch();
//Commit it  到(DB)里面

转载请注明出处:https://www.onexin.net/java-entry-learning-addbatch-usage/

相关文章:

1、Java 封装Encapsulation
https://www.onexin.net/java-encapsulation/

2、高性能、高流量Java Web站点打造的22条建议(转)
https://www.onexin.net/high-performance-high-traffic-sites-to-build-java-web-22-recommendations-rpm/

3、Java开源缓存框架介绍
https://www.onexin.net/java-open-source-caching-frameworks-introduced/

4、JAVA程序命名规范
https://www.onexin.net/java-program-naming-conventions/

5、Java随机一注双色球代码
https://www.onexin.net/the-java-random-a-note-color-ball-code/

Leave a Reply