wood burning stoves 2.0*
The moose likes JDBC and the fly likes Difference between execute() and excuteQuery() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Difference between execute() and excuteQuery()" Watch "Difference between execute() and excuteQuery()" New topic
Author

Difference between execute() and excuteQuery()

Praveen palukuri
Ranch Hand

Joined: Feb 10, 2005
Posts: 65
hi,
i tried to know the difference between execute() and executeQuery(). but i'm unalbe to know. if any one knows about this pls reply.

Thank U.
Sri Ram
Ranch Hand

Joined: Oct 03, 2005
Posts: 118
execute() is a generic method which can be called for retrieving data from the database as well updating the database. However it is never going to return you the ResultSet in case of retrieval or the number of rows updated in case of update/delete/insert. You might want to use it in places where you just want to test if the database access is a success or not.

On the other hand, executeQuery is very specific to retrieval of data from the database. It returns you a ResultSet which can be used to pull the data you need.

Also, The executeQuery() method takes a precompiled SQL statement as parameter and executes it.

Whereas, the execute() method simply executes an SQL statement without prior knowledge of the type of statement.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Actually the execute() method does return a ResultSet, if the SQL produces one. And it returns an update count, too, if the SQL produces one. From the documentation:
The execute method executes an SQL statement and indicates the form of the first result. You must then use the methods getResultSet or getUpdateCount to retrieve the result, and getMoreResults to move to any subsequent result(s).
Incidentally, the documentation is the answer to the original question.
 
 
subject: Difference between execute() and excuteQuery()
 
Similar Threads
execute() and perform()
Diff. between JDK 1.3 and JDK 1.5
diff bw execute and executeUpdate()
What is the difference between executeUpdate and execute?
Is there any difference between executeUpdate and execute?