• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to execute multiple different queries in one execute?

 
Sakina Shaikh
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33684
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried this:


 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33684
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Martin Vajsar
Sheriff
Pie
Posts: 3747
62
Chrome Netbeans IDE Oracle
  • 0
  • Mark post as helpful
  • send pies
  • 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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic