jdbc的批处理实现
来源:互联网 发布:海隆软件待遇好吗 编辑:程序博客网 时间:2024/05/21 22:53
jdbc的批处理实现
- 对于preparedStatement预处理执行sql语句的时候(这种情况是针对同一条sql语句被多次执行)
举例如下
package day10.wyn;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.Arrays;import org.junit.Test;import util.wyn.MyDBUtils;public class Batch { private Connection con=null; private PreparedStatement pstmt=null; private ResultSet rs=null; @Test public void groupD() throws SQLException{ con=MyDBUtils.getCon(); String sql="insert into user(username,password) values (?,?)"; pstmt=con.prepareStatement(sql); for(int i=1;i<500;i++){ pstmt.setString(1, "wang"+i); pstmt.setString(2, "123456"); pstmt.addBatch(); } int [] result=pstmt.executeBatch(); System.out.println(Arrays.toString(result)); MyDBUtils.getClose(con, pstmt, rs); }}
2 . 对于Statement执行sql语句的时候(这种情况针对执行不同的sql语句)
举例如下
package day10.wyn;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.Arrays;import org.junit.Test;import util.wyn.MyDBUtils;public class Batch { private Connection con=null; private PreparedStatement pstmt=null; private ResultSet rs=null; @Test public void groupD1() throws SQLException{ Statement stmt=null; String a="huang"; String b="guo"; con=MyDBUtils.getCon(); String sql1="insert into user(username,password) values ('"+a+"','"+b+"');"; String sql2="insert into user(username,password) values ('"+a+"','"+b+"')"; stmt=con.createStatement(); stmt.addBatch(sql1); stmt.addBatch(sql2); int [] result=stmt.executeBatch(); System.out.println(Arrays.toString(result)); MyDBUtils.getClose(con, pstmt, rs); }}
0 0
- jdbc的批处理实现
- jdbc实现对mysql数据库的批处理
- 利用jdbc实现批处理
- JDBC批处理实现
- JDBC当中的批处理
- JDBC-Statement的批处理
- 关于JDBC的批处理
- Jdbc的批处理执行
- JDBC当中的批处理
- JDBC当中的批处理
- JDBC的批处理
- 【JDBC笔记】JDBC的批处理、事务等
- jdbc批处理的事务控制
- JDBC 的事务处理与批处理
- JDBC操作数据库的批处理
- JDBC批处理
- jdbc批处理
- JDBC批处理
- Mac 终端 停止android logcat命令的输出.退出logcat的执行。
- Python官方文档结构图
- POJ 3041 Asteroids(摧毁小行星,二分图)
- linux中fork()函数详解(原创!!实例讲解)
- MFC改变窗口的缺省风格
- jdbc的批处理实现
- Vue.js入门
- 最小总距离点的最优位置
- MFC动态改变窗口图标
- 第九周项目4-广义表算法库及应用(2)
- 歌星大奖赛
- IntelliJ IDEA激活码
- zbar 安装
- linux设备驱动程序之SPI nor flash