Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

executing an INSERT statement using a PreparedStatement

 
Heath Lilley
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering if anyone knew which method of a PreparedStatement is best suited for an INSERT statement. Is the executeUpdate the best choice?
 
Peter Tran
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heath,
If you have a lot of insert, I would recommend using a batch insert. With a PreparedStatment, you would execute stmt.addBatch(), then a stmt.executeBatch() at the end.
-Peter
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a single insert, you would use executeUpdate(). Remember that the main difference between executeUpdate() and executeQuery() is what they return. You could use executeQuery() to run an insert but you would get back an empty ResultSet.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic