119 lines
3.4 KiB
Java
119 lines
3.4 KiB
Java
/*
|
||
package com.ruoyi.web.Utils;
|
||
|
||
import com.ruoyi.system.domain.cost;
|
||
import com.ruoyi.system.domain.material;
|
||
import javax.swing.*;
|
||
import java.sql.*;
|
||
import java.util.List;
|
||
|
||
public class batchInsert extends JFrame {
|
||
|
||
public static Connection conn;
|
||
public static Statement stm;
|
||
public static PreparedStatement stmt;
|
||
public static ResultSet rs;
|
||
|
||
*/
|
||
/**
|
||
* 对数据库进行批量插入数据操作 执行次数100万
|
||
*//*
|
||
|
||
public static void insertMaterialBatch(List<material> list) throws Exception {
|
||
// 思路:将100万条数据分成n等份,1等份为1000条数据
|
||
// 如何实现?
|
||
// 1、必须将Connection接口的自动提交方式改为手动
|
||
// 2、利用Statement接口中的如下三个方法:addBatch、clearBath、executeBatch
|
||
conn = DataDBUtils.getConnection();
|
||
conn.setAutoCommit(false);
|
||
*/
|
||
/*stmt = conn.prepareStatement(
|
||
"insert into [dbo].[sapcontract_test](uid,bh,type,custom,salesman,project,htje,startdate,enddate,remark,htzt) values (?,?,?,?,?,?,?,?,?,?,?)");*//*
|
||
|
||
stmt = conn.prepareStatement(
|
||
"insert into c_material(material_id, material_xingh, material_guig, material_diany, material_dw,material_type_id) values (?,?,?,?,?,?)");
|
||
int count = 0;
|
||
System.err.println("Start");
|
||
for (material pay : list) {
|
||
count++;
|
||
stmt.setInt(1, pay.getMaterial_id());
|
||
stmt.setString(2, pay.getMaterial_xingh());
|
||
stmt.setString(3, pay.getMaterial_guig());
|
||
stmt.setString(4, pay.getMaterial_diany());
|
||
stmt.setString(5, pay.getMaterial_dw());
|
||
stmt.setString(6, pay.getMaterial_type_id());
|
||
|
||
stmt.addBatch();
|
||
if (count % 5000 == 0) {// 当增加了500个批处理的时候再提交
|
||
stmt.executeBatch();// 执行批处理
|
||
conn.commit();
|
||
}
|
||
}
|
||
|
||
stmt.executeBatch();// 执行批处理
|
||
conn.commit();
|
||
|
||
close(); // 关闭资源
|
||
|
||
}
|
||
|
||
*/
|
||
/**
|
||
* 对数据库进行批量插入数据操作 执行次数100万
|
||
*//*
|
||
|
||
public static void insertCostBatch(List<cost> list) throws Exception {
|
||
// 思路:将100万条数据分成n等份,1等份为1000条数据
|
||
// 如何实现?
|
||
// 1、必须将Connection接口的自动提交方式改为手动
|
||
// 2、利用Statement接口中的如下三个方法:addBatch、clearBath、executeBatch
|
||
conn = DataDBUtils.getConnection();
|
||
conn.setAutoCommit(false);
|
||
*/
|
||
/*stmt = conn.prepareStatement(
|
||
"insert into [dbo].[sapcontract_test](uid,bh,type,custom,salesman,project,htje,startdate,enddate,remark,htzt) values (?,?,?,?,?,?,?,?,?,?,?)");*//*
|
||
|
||
stmt = conn.prepareStatement(
|
||
"insert into c_material_cost(cost_id, cost_material_id, cost_cl_id, cost_cl_qty, cost_cl_qty_2) values (?,?,?,?,?)");
|
||
int count = 0;
|
||
System.err.println("Start");
|
||
for (cost pay : list) {
|
||
count++;
|
||
stmt.setInt(1, pay.getCost_id());
|
||
stmt.setInt(2, pay.getCost_material_id());
|
||
stmt.setString(3, pay.getCost_cl_id());
|
||
stmt.setString(4, pay.getCost_cl_qty());
|
||
stmt.setString(5, pay.getCost_cl_qty_2());
|
||
|
||
stmt.addBatch();
|
||
if (count % 5000 == 0) {// 当增加了500个批处理的时候再提交
|
||
stmt.executeBatch();// 执行批处理
|
||
conn.commit();
|
||
}
|
||
}
|
||
|
||
stmt.executeBatch();// 执行批处理
|
||
conn.commit();
|
||
|
||
close(); // 关闭资源
|
||
|
||
}
|
||
|
||
public static void close() {
|
||
try {
|
||
if (rs != null)
|
||
rs.close();
|
||
if (stmt != null)
|
||
stmt.close();
|
||
if (stm != null)
|
||
stm.close();
|
||
if (conn != null)
|
||
conn.close();
|
||
} catch (SQLException e) {
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
|
||
}
|
||
*/
|