>
>Raymond Chui <[EMAIL PROTECTED]> wrote:

>> 2) Use batched update. Requires a JDBC 2 compliant driver.
>> The purpose is to reduce the number of server roundtrips.

>What is batched update?

PreparedStatement.addBatch() and PreparedStatement.executeBatch().

Something like this:


PreparedStatement ps = con.prepareStatement("INSERT INTO XX VALUES 
(?,?,?)");


//later...
for (int i=0; i<100 /*maybe?*/; i++) {
   // Get data
   ps.setInt(1,ival);
   ps.setString(2,sval);
   ps.setFloat(3,fval);
   ps.addBatch();     // Add one record to the batch
}

// Note! nothing sent to server yet.
int sv[] = ps.executeBatch();
// Now, 100 lines are inserted in one go!
con.commit();
// Commit 100 lines



/Per Schr�der
http://developer.mimer.com

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly

Reply via email to