Efficient way to do batch INSERTS with JDBC

前端 未结 10 711
无人共我
无人共我 2020-11-22 14:12

In my app I need to do a lot of INSERTS. Its a Java app and I am using plain JDBC to execute the queries. The DB being Oracle. I have enabled batching though, so it saves me

10条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 14:53

    The Statement gives you the following option:

    Statement stmt = con.createStatement();
    
    stmt.addBatch("INSERT INTO employees VALUES (1000, 'Joe Jones')");
    stmt.addBatch("INSERT INTO departments VALUES (260, 'Shoe')");
    stmt.addBatch("INSERT INTO emp_dept VALUES (1000, 260)");
    
    // submit a batch of update commands for execution
    int[] updateCounts = stmt.executeBatch();
    

提交回复
热议问题