• 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

how to execute multiple different queries in one execute?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to execute the multiple queries or job in one execute. Something like this eg:




Or multiple select queries.Queries will be dynamic.

But I am not able to do this.What is the way to run multiple queries separated by semi colon.
 
author & internet detective
Posts: 41919
910
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

Sakina Shaikh wrote:But I am not able to do this.What is the way to run multiple queries separated by semi colon.


Don't. This isn't supported by all databases/drivers.

If you can only have one database roundtrip, you should use a stored procedure.

If you only had insert/update/delete, you could use addBatch()/executeBatch() to do all of them in one database roundtrip. Select can't be included though.
 
Sakina Shaikh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried this:


 
Jeanne Boyarsky
author & internet detective
Posts: 41919
910
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
You generally want to state what problem you had and not just post the code you tried. I see two problems though:
1) You always use result[0] and not the index of the statement. Which means this runs the select statement repeatedly.
2) The statements could be run out of order if you have a select after the insert/update.
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the ranch, Sakina!

Have you achieved what you wanted?

I noticed you've fixed the result[0] bug pointed out by Jeanne in your post. To prevent a confusion, please refrain from editing posts others have already replied to in a manner that makes the replies meaningless; or at least put a note into the edited post so that the changes are obvious. Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic