1. Change the jdbc operation to batch processing addBatch (); // Add Batch Processing
2. Use PreparedStatement
Code:
Eg:
[Java]
Connection conn = DBUtils. getInstance (). getConnetion ();
Conn. setAutoCommit (false );
PreparedStatement pstmt = null;
Try
Pstmt = conn. preparedStatement ("insert into test1 (a, B) vlaues (?,?) ");
Pstmt. clearBatch ();
For (int I = 0; I <100000; I ++ ){
Pstmt. setInt (1, I );
Pstmt. setString (2, "value" + I );
Pstmt. addBatch ();
If (I % 10000 ){
Pstmt.exe cutbeBatch ();
}
}
Pstmt.exe cuteBatch ();
Conn. commit ();
} Catch (Exception e ){
Conn. rollback ();
} Finally {
Conn. setAutocommit (true );
} 1. Change the jdbc operation to batch processing addBatch (); // Add Batch Processing
2. Use PreparedStatement
Code:
Eg:
[Java]
Connection conn = DBUtils. getInstance (). getConnetion ();
Conn. setAutoCommit (false );
PreparedStatement pstmt = null;
Try
Pstmt = conn. preparedStatement ("insert into test1 (a, B) vlaues (?,?) ");
Pstmt. clearBatch ();
For (int I = 0; I <100000; I ++ ){
Pstmt. setInt (1, I );
Pstmt. setString (2, "value" + I );
Pstmt. addBatch ();
If (I % 10000 ){
Pstmt.exe cutbeBatch ();
}
}
Pstmt.exe cuteBatch ();
Conn. commit ();
} Catch (Exception e ){
Conn. rollback ();
} Finally {
Www.2cto.com
Conn. setAutocommit (true );
}
Author; tbwshc