aspose file tools*
The moose likes JDBC and the fly likes executing an INSERT statement using a PreparedStatement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "executing an INSERT statement using a PreparedStatement" Watch "executing an INSERT statement using a PreparedStatement" New topic
Author

executing an INSERT statement using a PreparedStatement

Heath Lilley
Ranch Hand

Joined: Jan 09, 2001
Posts: 72
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

Joined: Jan 02, 2001
Posts: 783
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

Joined: May 05, 2000
Posts: 13974
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.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: executing an INSERT statement using a PreparedStatement