• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

execute batch is not executing all the queries.

 
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
author & internet detective
Posts: 39956
804
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Posts: 39956
804
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 763
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok.. thanks a lot jeanne
 
This parrot is no more. It has ceased to be. Now it's a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
    Bookmark Topic Watch Topic
  • New Topic