After a connection is obtained we can interact with the database with sql statement.
Usually the sql statement is executed by Statement
interface returned from Connection.
JDBC Statement
is for general-purpose access to your database.
It is useful when using static SQL statements.
The Statement interface cannot accept parameters.
Statement object is created using the Connection object's createStatement() method as follows:
Statement stmt = conn.createStatement( );
We can use Statement to execute a SQL statement with one of its three execute methods.
boolean execute(String SQL)
int executeUpdate(String SQL)
ResultSet executeQuery(String SQL)
executes a SELECT statement and get result back.
Returns a ResultSet object.
We need to close a Statement
object to clean up the allocated database resources.
If we close the Connection object first, it will also close the Statement object.
Statement stmt = null; try { stmt = conn.createStatement( ); stmt execuate method(); } catch (SQLException e) { } finally { stmt.close(); }