67,513
社区成员
发帖
与我相关
我的任务
分享
String connString="jdbc:mysql://xxxx:3306/db?rewriteBatchedStatements=true";;
BufferedReader br=new BufferedReader(new FileReader("src/222.txt"));
String line="";
con=(Connection) connpool.getConnection();
con.setAutoCommit(false);
PreparedStatement pst = (PreparedStatement) con.prepareStatement("insert into jp115 (a,b,c,d) values(?,?,?,?)");
// PreparedStatement pst = (PreparedStatement) con.prepareStatement(sqlstr,PreparedStatement.RETURN_GENERATED_KEYS);
int j=1;
while((line=br.readLine())!=null){
pst.setString(1, line.split(":")[0]);
pst.setString(2, line.split(":")[1]);
pst.setString(3, line.split(":")[2]);
pst.setString(4, line.split(":")[3]);
pst.addBatch();
if (j%500==0){
pst.executeBatch();
con.commit();
pst.clearBatch();
System.out.print(j+"提交成功");
}
j++;
}