The Statement interface belongs to the java.sql package and is used to execute SQL statements from a Java application. A Statement object is created using the createStatement() method of the Connection interface. It can execute SQL commands such as SELECT, INSERT, UPDATE, and DELETE. The executeQuery() method is generally used for SELECT statements, while executeUpdate() is used for INSERT, UPDATE, and DELETE operations. The execute() method can be used when the type of SQL statement or its result is not known in advance. After completing database operations, the Statement should be closed to release resources.
Methods of Statement Interface
| Methods |
|---|
|
Executes a |
|
Executes |
|
Executes the specified SQL statement and returns |
|
Closes the |
|
Returns the maximum number of rows that a |
|
Sets the maximum number of rows that a |
|
Returns the maximum time in seconds allowed for executing a SQL statement. |
|
Sets the maximum time in seconds allowed for executing a SQL statement. |
|
Cancels the current SQL statement if the JDBC driver supports cancellation. |
|
Clears all warnings associated with the |
|
Returns the first warning reported by the |
|
Returns the |
|
Checks whether the |
|
Adds an SQL statement to the current batch of commands. |
|
Removes all SQL statements currently stored in the batch. |
|
Executes all SQL statements stored in the batch and returns an array containing the update counts. |
|
Retrieves the current result as a |
|
Returns the current result as an update count, or |
|
Moves to the next result produced by the statement. |
