File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes execute() and executeQuery() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "execute() and executeQuery()" Watch "execute() and executeQuery()" New topic

execute() and executeQuery()

deepashree deval

Joined: Oct 20, 2008
Posts: 12
Can anybody tell me when shall I use the method execute() , executeQuery() what is the difference

[Updated Topic - Dave]
[ October 21, 2008: Message edited by: David O'Meara ]
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

one returns a ResultSet and the other does not. If you want a ResultSEt (eg from a query) then use that one.
Brian Mozhdehi
Ranch Hand

Joined: Aug 17, 2006
Posts: 81
You may also call Statement.getResultSet() if you choose to use execute() and the statement produces a ResultSet. executeQuery() is a conveience method when running SELECT statements as you of course are looking for a Result set usually in this case.
I agree. Here's the link:
subject: execute() and executeQuery()
It's not a secret anymore!