• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Batch updates using PreparedStatement

 
Alok Pota
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an insert statement that inserts a BLOB into the table, and this statement is executed in a loop for about 100 times. I would like to be able to batch the individual
statements. Can it be done?
Will it be faster than issuing 100 different statements to the connection.
 
karim qazi
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can try something like this...
Statement statement = connection.createStatement();
//whatever you are looping through
while(true){
String sqlString = "Insert into table (name)values
('" + name + "')";
statement.addBatch(sqlString);
}
statement.executeBatch();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic