• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

execute batch is not executing all the queries.

 
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok.. thanks a lot jeanne
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic