This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Difference between execute,  executeQuery, executeUpdate 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 "Difference between execute,  executeQuery, executeUpdate" Watch "Difference between execute,  executeQuery, executeUpdate" New topic

Difference between execute, executeQuery, executeUpdate

Mike lothar

Joined: Nov 16, 2004
Posts: 22
Hi All,
what is the Difference between execute, executeQuery, executeUpdate. please tell what will each method will return?.

Thank you
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

The best place to find answers to questions like this is the Javadocs:

boolean execute()
Executes the SQL statement in this PreparedStatement object, which may be any kind of SQL statement.

ResultSet executeQuery()
Executes the SQL query in this PreparedStatement object and returns the ResultSet object generated by the query.

int executeUpdate()
Executes the SQL statement in this PreparedStatement object, which must be an SQL INSERT, UPDATE or DELETE statement; or an SQL statement that returns nothing, such as a DDL statement.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Lalit Mehra
Ranch Hand

Joined: Jun 08, 2010
Posts: 384

the names are self explanatory dear friend ...

executeUpdate() -> database UPDATE statements
executeQuery() -> database QUERY statements
execute() -> anything that comes in
Deepthi Tanguturi

Joined: Sep 06, 2011
Posts: 17
executeQuery()---for getting the data from database
executeUpdate()---for insert,update,delete
execute()-any kind of operations
Vigneswaran Marimuthu

Joined: Aug 30, 2011
Posts: 24

executeQuery() --- This is used generally for reading the content of the database. The output will be in the form of ResultSet. Generally SELECT statement is used.

executeUpdate() --- This is generally used for altering the databases. Generally DROP TABLE or DATABASE, INSERT into TABLE, UPDATE TABLE, DELETE from TABLE statements will be used in this. The output will be in the form of int. This int value denotes the number of rows affected by the query.

execute() --- If you dont know which method to be used for executing SQL statements, this method can be used. This will return a boolean. TRUE indicates the result is a ResultSet and FALSE indicates it has the int value which denotes number of rows affected by the query.


I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Difference between execute, executeQuery, executeUpdate
jQuery in Action, 3rd edition