package Jdbcday02;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class TestBatchAdvance {
public static void main(String[] args) {
testBatch();
}
public static void testBatch(){
String sql="insert into mytemp values(?,?)";
try {
Connection conn=
ConnectionUtils.openConnection();
conn.setAutoCommit(false);
PreparedStatement psmt=conn.prepareStatement(sql);
for (int i = 0; i < 10000; i++) {
psmt.setInt(1, i);
psmt.setString(2, "values"+i);
psmt.addBatch(); //添加到批处理上
if (i%1000==0) {
psmt.executeBatch(); //每1000次一提交
}
psmt.executeBatch();
}
conn.commit();
ConnectionUtils.closeStatement(psmt);
ConnectionUtils.closeConnection(conn);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
jdbc批处理ad使用
最新推荐文章于 2024-06-19 00:56:06 发布