try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(o_url, userName, password);
conn.setAutoCommit(false);
String sql = "INSERT adlogs(ip,website,yyyymmdd,hour,object_id) VALUES(?,?,?,?,?)";
PreparedStatement prest = conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
for(int x = 0; x < size; x++){
prest.setString(1, "192.168.1.1");
prest.setString(2, "localhost");
prest.setString(3, "20081009");
prest.setInt(4, 8);
prest.setString(5, "11111111");
prest.addBatch();
}
prest.executeBatch();
conn.commit();
conn.close();
} catch (SQLException ex) {
Logger.getLogger(MyLogger.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(MyLogger.class.getName()).log(Level.SEVERE, null, ex);
}
conn.setAutoCommit(false);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
for(int x = 0; x < size; x++){
stmt.addBatch("INSERT INTO adlogs(ip,website,yyyymmdd,hour,object_id) VALUES('192.168.1.3', 'localhost','20081009',8,'23123')");
}
stmt.executeBatch();
conn.commit();
conn.setAutoCommit(false);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
for(int x = 0; x < size; x++){
stmt.execute("INSERT INTO adlogs(ip,website,yyyymmdd,hour,object_id) VALUES('192.168.1.3', 'localhost','20081009',8,'23123')");
}
conn.commit();
String sql = "insert into table *****";
con.setAutoCommit(false);
ps = con.prepareStatement(sql);
for(int i=1; i<65536; i++){
ps.addBatch();
// 1w条记录插入一次
if (i % 10000 == 0){
ps.executeBatch();
con.commit();
}
}
// 最后插入不足1w条的数据
ps.executeBatch();
con.commit();
long start = System.currentTimeMillis();
DaoRecord daoRecord = new DaoRecord();
List<T> list = new ArrayList<T>();
for(int i = 1; i <= 1000; i++){
for(int j = 1; j <= 1000; j++){
T t = new T();
t.setI(i);
t.setJ(j);
list.add(t);
}
}
daoRecord.InsertBatch(list);
System.out.println("耗时:" + (System.currentTimeMillis()-start)+"毫秒");
public void InsertBatch(List<T> list){
String sql = "insert into t(go,back) values(?,?)";
DBHelper dbh = new DBHelper(sql);
Connection conn = dbh.returnConn();
try {
conn.setAutoCommit(false);//注意此句一定要为false,原因见第一篇参考文献
PreparedStatement ps = conn.prepareStatement(sql);
for(int i = 0; i < list.size(); i++){
ps.setInt(1, list.get(i).getI());
ps.setInt(2, list.get(i).getJ());
ps.addBatch();
if (i % 10000 == 0){
ps.executeBatch();
conn.commit();
}
}
ps.executeBatch();
conn.commit();
conn.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有