aspose file tools*
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
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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30919
    
158

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Diff bet execute() and executeQuery()