Java Reference
In-Depth Information
public PreparedStatement prepareStatement(String sql) throws SQLEx-
ception. Creates a prepared SQL statement. The SQL is sent to the
database for precompilation.
public PreparedStatement prepareStatement(String sql, int resultSet-
Type, int concurrency, int holdability) throws SQLException. Creates
a prepared statement using the specified properties for result sets. The
resultSetType is either TYPE_FORWARD_ONLY,
TYPE_SCROLL_INSENSITIVE, or TYPE_SCROLL_SENSITIVE.
The concurrency type is either CONCUR_READ_ONLY or CONCUR_
UPDATABLE, and holdability is either HOLD_CURSORS_OVER_
COMMIT or CLOSE_CURSORS_AT_COMMIT.
public PreparedStatement prepareStatement(String sql, int resultSet-
Type, int concurrency) throws SQLException. Similar to the previous
method, except that only the scroll type and concurrency type are
specified.
public PreparedStatement prepareStatement(String sql, int pk) throws
SQLException. Creates a prepared SQL statement used for INSERT
statements in a database that generates the primary key for you. The
possible values of pk are RETURN_GENERATED_KEYS or NO_GEN-
ERATED_KEYS, and only applies to INSERT statements.
public PreparedStatement prepareStatement(String sql, String [ ] keys)
throws SQLException. Creates a prepared SQL statement used for
INSERT statements in a database that generates the primary key for you.
The array of Strings represents the column name or names that compose
the primary key.
public PreparedStatement prepareStatement(String sql, int [ ] keys)
throws SQLException. Similar to the previous method, except that the
array of columns is denoted by the column index instead of the column
name.
Notice that these last three prepareStatement() methods contain information
about autogenerated primary keys, which only applies to INSERT statements.
Creating a Statement did not involve the actual SQL, since it is done using
the Statement interface; however, when creating a prepared statement,
SQL is needed so the statement can be precompiled and the
PreparedStatement object can be created.
The following code demonstrates preparing a statement using a connection:
PreparedStatement insert = connection.prepareStatement(
“INSERT INTO Employees VALUES (?, ?, ?, ?)”);
Search WWH ::




Custom Search