| 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
internet detective
Marshal
Joined: May 26, 2003
Posts: 26192
|
|
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.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Sakina Shaikh
Greenhorn
Joined: Jun 09, 2012
Posts: 2
|
|
I have tried this:
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26192
|
|
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
Bartender
Joined: Aug 22, 2010
Posts: 2331
|
|
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.
|
 |
 |
|
|
subject: how to execute multiple different queries in one execute?
|
|
|