*
The moose likes JDBC and the fly likes execute batch is not executing all the queries. 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 "execute batch is not executing all the queries." Watch "execute batch is not executing all the queries." New topic
Author

execute batch is not executing all the queries.

Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 753
Hi I am trying to perform the batch execution of 3 delete statement which perform delete operation for three different table.

but data is getting deleted for only one table.



Data is getting deleted for only bellow query.



Thanks & Regards,
[ November 10, 2008: Message edited by: Jigar Naik ]

Jigar Naik


Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

Jigar,
Let's walk though what is happening here:

// create a new prepared statement (let's call it ps1) and store a reference to it in ps
ps = connection.prepareStatement(SchedulerQueryConstants.DELETE_FROM_SCHEDULER_JOB);
// set parameter on ps1
ps.setString(1, jobKey);
// store this SQL statement in ps1
ps.addBatch();

// create a new prepared statement (let's call it ps2) and store a reference to it in ps
ps = connection.prepareStatement(SchedulerQueryConstants.DELETE_FROM_SCHEDULED_CAMPAIGN);
// set parameter on ps2
ps.setString(1, jobKey);
// store this SQL statement in ps2
ps.addBatch();

// create a new prepared statement (let's call it ps3) and store a reference to it in ps
ps = connection.prepareStatement(SchedulerQueryConstants.DELETE_FROM_JOB_SCHEDULE_TIME);
// set parameter on ps3
ps.setString(1, jobKey);
// store this SQL statement in ps3
ps.addBatch();

// execute all the stored SQL statements on ps3 (because that is what ps is pointing to now)
ps.executeBatch();


ps1 and ps2 are now "orphaned". They will be garbage collected, but never run.


[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
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 753
Thanks Jeanne,

I got your point. So Does that means what i am trying to achieve using prepared statement is not possible?

I did it using Statement.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

Originally posted by Jigar Naik:
So Does that means what i am trying to achieve using prepared statement is not possible?

Right. You can add the same statement with multiple parameters via a prepared statement. But not different statements.
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 753
ok.. thanks a lot jeanne
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: execute batch is not executing all the queries.
 
Similar Threads
Adding code to return an ArrayList of objects
executeBatch() amount of success rows
How to delete a record from a table without a primary key
What problem with this batch update ?
Prepared Statement