- 8 seconds to add 20,000 data in bulk.
- try {
- String url = "Jdbc:oracle:thin: @IP: 1521:ORCL"; //ORCL is the SID of the database
- 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);
- //Turn off transaction autocommit
- 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 ());
- //Add a SQL command to the command list
- Pst.addbatch ();
- }
- //Perform batch updates
- Pst.executebatch ();
- //Statement execution complete, commit this transaction
- Con.commit ();
- Long endTime = System.currenttimemillis ();
- System.out.println ("spents:" + (Endtime-starttime));
- Pst.close ();
- Con.close ();
- } catch (ClassNotFoundException e) {
- E.printstacktrace ();
- } catch (SQLException e) {
- E.printstacktrace ();
- }
Java BULK Insert Data (Oracle)