This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes JDBC 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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30392
    
150

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.


[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
 
wood burning stoves
 
subject: Diff bet execute() and executeQuery()