Difference Between executeQuery(), executeUpdate() and execute() Methods in Java
Contents
executeQuery() Vs executeUpdate() Vs execute()
- executeQuery() Vs executeUpdate() Vs execute() are the methods of java.sql.Statement interface of JDBC which are used to execute SQL statements.
- executeQuery() command used for getting the data from database whereas executeUpdate() command used for insert,update,delete or execute() command used forany kind of operations.

Comparison Chart
executeQuery() | executeUpdate() | execute() |
---|---|---|
executeQuery() method used to retrieve some data from database. | executeUpdate() method used for update or modify database. | execute() use for any SQL statements. |
It returns an object of the class
ResultSet executeQuery (String sql) throws SQLException |
It returns an integer value.
int executeUpdate(String sql) throws SQLException |
It returns a boolean value.
int executeUpdate(String sql) throws SQLException |
This method is normally used to execute SELECT queries. | This method Is used to execute non SELECT queries.
|
This method can be used to execute any type of SQL statement. |
Example:
|
Example:
|
Example:
|