- public ResultSet executeQuery( String sql ) throws SQLException
It executes an SQL statement that returns a single ResultSet
object.
It is for any SQL calls that expect to return data from the database; e.g.,
ResultSet rset = stmt.executeQuery(
"SELECT ename FROM emp WHERE eid='7772413'" );
- public int executeUpdate( String sql ) throws SQLException
It executes an SQL INSERT
, UPDATE
, or DELETE
statement.
In addition, SQL statements that return nothing, such as SQL DDL statements, can be executed.
This method returns the number of affected rows; e.g.,
stmt.executeUpdate( "INSERT INTO customers VALUES(
'Pokemon', '123456789', 0 )" );
- public boolean execute( String sql ) throws SQLException
It is for situations in which you do not know whether the SQL being executed is a query or update. For example,
try {
stmt.execute( "DROP TABLE people" );
stmt.execute( "DROP TYPE person FORCE" );
stmt.execute( "DROP TYPE address FORCE" );
}
catch( SQLException e ) { System.out.println( e ); }
†This usually happens when the application is executing dynamically created SQL statements.
The class