File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and the fly likes Number of commands in a batch Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Number of commands in a batch" Watch "Number of commands in a batch" New topic

Number of commands in a batch

Tom Field

Joined: Feb 18, 2009
Posts: 1

I use a PreparedStatemen as such: I compile a sql in the PreparedStatement. I set the parameters, Add them to the batch using addBatch() method, set the parameters, addBatch, ....
After a while I would like to see how many of these commands(the set of parameters) are currently in the batch. I mean before I execute the executeBatch method.
I would think this would be a method on PreparedStatement (or Statement), but I can't find any solution except keeping a counter for each PreparedStatement.
I don't like this very much so I was wondering if there isn't another method to achieve this.

Thanks in advance!

Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 30138

Tom Field wrote:but I can't find any solution except keeping a counter for each PreparedStatement.

That's what I would do too.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Doesn't the collection from which you get the parameters for setting in the preparedstatement have a method which returns the size?
Consider Paul's rocket mass heater.
subject: Number of commands in a batch
Similar Threads
How to deal with single Erros IN batch updates in JDBC applications
How can I do batch updates using PreparedStatements rather than Statements?
Problems with jdbc and tomcat
what is difference between JDBC1 and JDBC2 ?
multiple prepared statemnets using executeBatch