executeQuery, executeUpdate and execute

executeQuery

  • public ResultSet executeQuery() throws SQLException
  • Executes the SQL query in this PreparedStatement object and returns the ResultSet object generated by the query.
  • Returns: a ResultSet object that contains the data produced by the query; never null
  • Throws: SQLException – if a database access error occurs or the SQL statement does not return a ResultSet object2

executeUpdate

  • public int executeUpdate() throws SQLException
  • 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.
  • Returns: either (1) the row count for INSERT, UPDATE, or DELETE statements or (2) 0 for SQL statements that return nothing
  • Throws: SQLException – if a database access error occurs or the SQL statement returns a ResultSet object.

execute

  • public boolean execute() throws SQLException
  • Executes the SQL statement in this PreparedStatement object, which may be any kind of SQL statement. Some prepared statements return multiple results; the execute method handles these complex statements as well as the simpler form of statements handled by the methods executeQuery and executeUpdate.
  • The execute method returns a boolean to indicate the form of the first result. You must call either the method getResultSet or getUpdateCount to retrieve the result; you must call getMoreResults to move to any subsequent result(s).
  • Returns: true if the first result is a ResultSet object; false if the first result is an update count or there is no result
  • Throws: SQLException – if a database access error occurs or an argument is supplied to this method

 

Rate this post

Leave a Reply