1 using JDBC for bulk execution SQL in the actual project development, sometimes you need to send a batch of SQL statement execution to the database, you should avoid sending execution to the database, but should adopt the batch processing mechanism of JDBC, in order to improve the execution efficiency.
Package Dbex.mysql;import Java.io.ioexception;import Java.sql.connection;import java.sql.preparedstatement;import Java.sql.resultset;import java.sql.sqlexception;import java.util.date;import Dbex. Dbutil;public class Batchsql {/** * @throws IOException * @throws SQLException * @Title: Dobatch * @Description: Batch operation with JDBC * @param * @throws */void Dobatch () throws SQLException, ioexception{ Connection conn=dbutil.getconnection (); PreparedStatement ppst = null; ResultSet rs = null; try {Long startTime = System.currenttimemillis (); Ppst = Conn.preparestatement ("INSERT into CLOB values (?, ' the ' This is a test for batch SQL ')"); for (int i = 222; i < 100222; i++) {ppst.setint (1, i); Ppst.addbatch (); } ppst.executebatch (); Long endTime = System.currenttimemillis (); System.out.println (New Date (). toLocaleString () + "Execute batchThe amount of time "+ (Endtime-starttime)/1000+" s "); } catch (Exception e) {e.printstacktrace (); }finally{Dbutil.closeall (conn, ppst, RS); }} public static void Main (string[] args) throws SQLException, IOException {new Batchsql (). Dobatch (); }}
Advantages
JDBC Review 4 batch execution SQL