Red Hat Enterprise linux 7与linxu6命令的变化,运行级别,多ip网卡配置,nmtui功能的使用及说明
2016-03-09 16:03
567 查看
在数据库中执行一个批处理SQL语句
With batch updating, a set of SQL statements is assembled and then sent altogether to the database for execution. Batch updating can improve performance.
This example creates a batch of insert statements. Auto-commit is disabled so that you have the choice of committing or not in the event of an exception.
java 代码
With batch updating, a set of SQL statements is assembled and then sent altogether to the database for execution. Batch updating can improve performance.
This example creates a batch of insert statements. Auto-commit is disabled so that you have the choice of committing or not in the event of an exception.
java 代码
try { // Disable auto-commit connection.setAutoCommit(false); // Create a prepared statement String sql = "INSERT INTO my_table VALUES(?)"; PreparedStatement pstmt = connection.prepareStatement(sql); // Insert 10 rows of data for (int i=0; i<10; i++) { pstmt.setString(1, ""+i); pstmt.addBatch(); } // Execute the batch int [] updateCounts = pstmt.executeBatch(); // All statements were successfully executed. // updateCounts contains one element for each batched statement. // updateCounts[i] contains the number of rows affected by that statement. processUpdateCounts(updateCounts); // Since there were no errors, commit connection.commit(); } catch (BatchUpdateException e) { // Not all of the statements were successfully executed int[] updateCounts = e.getUpdateCounts(); // Some databases will continue to execute after one fails. // If so, updateCounts.length will equal the number of batched statements. // If not, updateCounts.length will equal the number of successfully executed statements processUpdateCounts(updateCounts); // Either commit the successfully executed statements or rollback the entire batch connection.rollback(); } catch (SQLException e) { } public static void processUpdateCounts(int[] updateCounts) { for (int i=0; i<updateCounts.length; i++) { if (updateCounts[i] >= 0) { // Successfully executed; the number represents number of affected rows } else if (updateCounts[i] == Statement.SUCCESS_NO_INFO) { // Successfully executed; number of affected rows not available } else if (updateCounts[i] == Statement.EXECUTE_FAILED) { // Failed to execute } } }
相关文章推荐
- linux tar 解压命令总结
- Linux下C程序的编辑,编译和运行以及调试
- C#与linux 时间戳互转
- linux第9天 UDP
- RedHat系统下安装CentOS系统的yum
- 那些年掉进的坑---内存踩踏实例记录
- CentOS 6 配置公共key认证服务
- CentOS6.3编译安装 Erlang 和 RabbitMQ3.4.3
- Linux基础之Vi编辑器快捷键
- 3G模块(U6300)linux下拨号上网
- linux7的网卡命名机制,名称组成格式;
- Linux下简单线程池的实现
- Ubuntu 14.04安装搜狗拼音linux版应该注意的问题
- Linux查看设备被哪个进程占用
- .Net Core CLI在CentOS7的安装及使用简介
- linux下修改MAC地址方法
- C/C++ makefile自动生成工具(comake2,autotools,linux),希望能为开源做点微薄的贡献!
- 为Linux新增静态路由以便用户手工配置
- centos7 下GPRS-Modem 短信猫配置以及发送短信调试说明
- linux与windows的文本文件之间的转换