This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Diff bet execute() and executeQuery() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Diff bet execute() and executeQuery()" Watch "Diff bet execute() and executeQuery()" New topic
Author

Diff bet execute() and executeQuery()

Navin Pillu
Ranch Hand

Joined: Apr 19, 2005
Posts: 103
Hi

Can anybody tell me what is the difference between execute(), executeQuery()?

As per specification on sun's site

1. executeQuery is designed for statements that produce a single resultset such as SELECT statement

2. execute is used to execute statements that returns more than one result set, more than one update count, or combination of two.

Actually 2nd point i could not understand. How statements return more than one resultset. If possible give example also.

Thanks
stu derby
Ranch Hand

Joined: Dec 15, 2005
Posts: 333
The ability to have multiple ResultSets is dependent on features of your driver and database; not all driver/database combinations support this but many do (although a lot of people don't use this feature even when available).

Here's an example:
http://www.javaworld.com/javaworld/jw-02-2000/jw-02-ssj-jdbc2.html
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31585
    
185

Originally posted by Navin Pillu:
2. execute is used to execute statements that returns more than one result set, more than one update count, or combination of two.

This is more frequent with a stored procedure returning multiple results.


[OCA 8 book] [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
Navin Pillu
Ranch Hand

Joined: Apr 19, 2005
Posts: 103
Hi stu,Jeanne

This really helped me a lot. Thanks for giving reply. Thanks to JavaWorld also.

Thanks & Regards
Navin
 
rocket mass heater kickstarter
 
subject: Diff bet execute() and executeQuery()