This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan 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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 29220
    
135

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Diff bet execute() and executeQuery()
 
Similar Threads
execute() and executeQuery()
No resultset
Looks right to me
Is any problem with this code?
getting empty resultset