- 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();
- }
posted @
2015-11-06 12:37
java高级技术汇
阅读(
3282)
评论()
编辑
收藏
举报