jQuery in Action, 3rd edition
The moose likes JDBC and Relational Databases and the fly likes how to execute multiple different queries in one execute? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "how to execute multiple different queries in one execute?" Watch "how to execute multiple different queries in one execute?" New topic
Author

how to execute multiple different queries in one execute?

Sakina Shaikh
Greenhorn

Joined: Jun 09, 2012
Posts: 2
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

Joined: May 26, 2003
Posts: 32499
    
214

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Sakina Shaikh
Greenhorn

Joined: Jun 09, 2012
Posts: 2
I have tried this:


Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32499
    
214

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

Joined: Aug 22, 2010
Posts: 3718
    
  61

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.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: how to execute multiple different queries in one execute?
 
It's not a secret anymore!