• 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

Batch DB Updatation

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys !!!
Below is a piece of code:
try{
con.setAutoCommit(false);
Statement stmt = con.createStatement();
while(stToken.hasMoreElements())
stmt.addBatch(stToken.nextToken());
int[] updateCounts = stmt.executeBatch();
con.commit();
catch(BatchUpdateException bueExcep){}
Here, batch updations take place dynamically through a user interface wherein the user casn specify the sql scripts to be fired. However, for instance if the first sql script is correct but the ones later on are incorrect then the entire transaction should be rolled back since the entire code is within "con.setAutoCommit(false);" and "con.commit();". Unfortunately, this does not occur and the first script does get executed successfully. What should be done to rectify it !!!
Pls suggest.
Thanks Guys
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is behaviour is JDBC driver specific. I use Oracle thin drivers and they behave the same. It's all or nothing. The best you can do is validity checking of the fields before you add them to batch (unless you can find a different driver that behaves the way you want it to).
Jamie
 
Story like this gets better after being told a few times. Or maybe it's just a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic