http://www.theserverside.com/articles/article.tss?l=JDBCPerformance_PartIII

PreparedStatement ps = conn.prepareStatement(
   "INSERT into employees values (?, ?, ?)");

for (n = 0; n < 100; n++) {

  ps.setString(name[n]);
  ps.setLong(id[n]);
  ps.setInt(salary[n]);
  ps.addBatch();
}
ps.executeBatch();

only two network roundtrips are required?one to prepare the statement and another to execute the batch. Although more database CPU cycles are involved by using batches, performance is gained through the reduction of network roundtrips. Remember that the biggest gains in performance with JDBC drivers is found by reducing network communication between the JDBC driver and the database server.

Advertisements