Java 批量插入数据(Oracle)
时间:2021-07-01 10:21:17
帮助过:2人阅读
try {
String url = "jdbc:oracle:thin:@IP:1521:orcl";
String user = "oracle";
String password = "oracle";
StringBuffer sql = new StringBuffer();
sql.append("insert into ex_log (EX_LOG_ID,EX_LOG_DATE) values (?,?)");
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = (Connection) DriverManager.getConnection(url,user,password);
con.setAutoCommit(false);
Long startTime = System.currentTimeMillis();
PreparedStatement pst = (PreparedStatement) con.prepareStatement(sql.toString());
for (int i = 0; i < list.size(); i++) {
ExLog exLog = (ExLog)list.get(i);
pst.setString(1, exLog.getExLogId());
pst.setString(2, exLog.getExLogDate());
pst.addBatch();
}
pst.executeBatch();
con.commit();
Long endTime = System.currentTimeMillis();
System.out.println("用时:" + (endTime - startTime));
pst.close();
con.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
Java 批量插入数据(Oracle)
标签: