A Statement object is created using the createStatement() method in the Connection object.
The most important methods are executeQuery(), executeUpdate(), and execute(). As you create a Statement object with a SQL statement, the executeQuery() method takes an SQL string. It passes the SQL string to the underlying data source through the driver manager and gets the ResultSet back to the application program. The executeQuery() method returns only one RecordSet(). For those cases that returns more than one ResultSet, the execute() method should be used.
For SQL statements that do not retun a ResultSet like the UPDATE, DELETE, and DDL, statements, the Statement object ha the executeUpdate() method that takes a SQL string and returns an integer. This integer indicates the number of rows that are affected by the SQL statement.
The Statement object is best suited for ad-hoc SQL statements or SQL statements or SQL statements that are executed once.



No comments:
Post a Comment