This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes JDBC and Relational Databases 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 Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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
author & internet detective

Joined: May 26, 2003
Posts: 32507

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

That's what I would do too.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, 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?
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Number of commands in a batch
It's not a secret anymore!