A SQL statement is precompiled and stored in a
PreparedStatement object. This object can then be used to
efficiently execute this statement multiple times.
Note
The setter methods (setShort, setString,
and so on) for setting IN parameter values
must specify types that are compatible with the defined SQL type of
the input parameter. For instance, if the IN parameter has SQL type
INTEGER, then the method setInt should be used.
If arbitrary parameter type conversions are required, the method
setObject should be used with a target SQL type.
In the following example of setting a parameter, con represents
an active connection:
BigDecimal sal = new BigDecimal("153833.00");
PreparedStatement pstmt = con.prepareStatement("UPDATE EMPLOYEES
SET SALARY = ? WHERE ID = ?");
pstmt.setBigDecimal(1, sal);
pstmt.setInt(2, 110592);
Connection#prepareStatement, ResultSet
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | |
| public boolean | Returns: true if the first result is a ResultSet
object; false if the first result is an update
count or there is no resultExecutes the SQL statement in this |
| public default long | Returns: either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothingExecutes the SQL statement in this |
| public ResultSet | Returns: aResultSet object that contains the data produced by the
query; never nullExecutes the SQL query in this |
| public int | Returns: either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothingExecutes the SQL statement in this |
| public ResultSetMetaData | Returns: the description of aResultSet object's columns or
null if the driver cannot return a
ResultSetMetaData objectRetrieves a |
| public ParameterMetaData | Returns: aParameterMetaData object that contains information
about the number, types and properties for each
parameter marker of this PreparedStatement objectRetrieves the number, types and properties of this
|
| public void | |
| public void | setAsciiStream(int
the first parameter is 1, the second is 2, ... parameterIndex, InputStream the Java input stream that contains the ASCII parameter value x, int the number of bytes in the stream length)Sets the designated parameter to the given input stream, which will have the specified number of bytes. |
| public void | setAsciiStream(int
the first parameter is 1, the second is 2, ... parameterIndex, InputStream the Java input stream that contains the ASCII parameter value x, long the number of bytes in the stream length)Sets the designated parameter to the given input stream, which will have the specified number of bytes. |
| public void | setAsciiStream(int
the first parameter is 1, the second is 2, ... parameterIndex, InputStream the Java input stream that contains the ASCII parameter value x)Sets the designated parameter to the given input stream. |
| public void | setBigDecimal(int
the first parameter is 1, the second is 2, ... parameterIndex, BigDecimal the parameter value x)Sets the designated parameter to the given |
| public void | setBinaryStream(int
the first parameter is 1, the second is 2, ... parameterIndex, InputStream the java input stream which contains the binary parameter value x, int the number of bytes in the stream length)Sets the designated parameter to the given input stream, which will have the specified number of bytes. |
| public void | setBinaryStream(int
the first parameter is 1, the second is 2, ... parameterIndex, InputStream the java input stream which contains the binary parameter value x, long the number of bytes in the stream length)Sets the designated parameter to the given input stream, which will have the specified number of bytes. |
| public void | setBinaryStream(int
the first parameter is 1, the second is 2, ... parameterIndex, InputStream the java input stream which contains the binary parameter value x)Sets the designated parameter to the given input stream. |
| public void | |
| public void | setBlob(int
index of the first parameter is 1,
the second is 2, ... parameterIndex, InputStream An object that contains the data to set the parameter
value to. inputStream, long the number of bytes in the parameter data. length)Sets the designated parameter to a |
| public void | setBlob(int
index of the first parameter is 1,
the second is 2, ... parameterIndex, InputStream An object that contains the data to set the parameter
value to. inputStream)Sets the designated parameter to a |
| public void | setBoolean(int
the first parameter is 1, the second is 2, ... parameterIndex, boolean the parameter value x)Sets the designated parameter to the given Java |
| public void | setByte(int
the first parameter is 1, the second is 2, ... parameterIndex, byte the parameter value x)Sets the designated parameter to the given Java |
| public void | setBytes(int
the first parameter is 1, the second is 2, ... parameterIndex, byte[] the parameter value x)Sets the designated parameter to the given Java array of bytes. |
| public void | setCharacterStream(int
the first parameter is 1, the second is 2, ... parameterIndex, Reader the reader, int java.io.Reader object that contains the
Unicode datathe number of characters in the stream length)Sets the designated parameter to the given |
| public void | setCharacterStream(int
the first parameter is 1, the second is 2, ... parameterIndex, Reader the reader, long java.io.Reader object that contains the
Unicode datathe number of characters in the stream length)Sets the designated parameter to the given |
| public void | setCharacterStream(int
the first parameter is 1, the second is 2, ... parameterIndex, Reader the reader)java.io.Reader object that contains the
Unicode dataSets the designated parameter to the given |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | setDouble(int
the first parameter is 1, the second is 2, ... parameterIndex, double the parameter value x)Sets the designated parameter to the given Java |
| public void | setFloat(int
the first parameter is 1, the second is 2, ... parameterIndex, float the parameter value x)Sets the designated parameter to the given Java |
| public void | setInt(int
the first parameter is 1, the second is 2, ... parameterIndex, int the parameter value x)Sets the designated parameter to the given Java |
| public void | setLong(int
the first parameter is 1, the second is 2, ... parameterIndex, long the parameter value x)Sets the designated parameter to the given Java |
| public void | setNCharacterStream(int
of the first parameter is 1, the second is 2, ... parameterIndex, Reader the parameter value value, long the number of characters in the parameter data. length)Sets the designated parameter to a |
| public void | setNCharacterStream(int
of the first parameter is 1, the second is 2, ... parameterIndex, Reader the parameter value value)Sets the designated parameter to a |
| public void | |
| public void | |
| public void | |
| public void | setNString(int
of the first parameter is 1, the second is 2, ... parameterIndex, String the parameter value value)Sets the designated parameter to the given |
| public void | setNull(int
the first parameter is 1, the second is 2, ... parameterIndex, int the SQL type code defined in sqlType)java.sql.TypesSets the designated parameter to SQL |
| public void | |
| public void | |
| public void | |
| public void | setObject(int
the first parameter is 1, the second is 2, ... parameterIndex, Object the object containing the input parameter value x, int the SQL type (as defined in java.sql.Types) to be
sent to the database. The scale argument may further qualify this type. targetSqlType, int for scaleOrLength)java.sql.Types.DECIMAL
or java.sql.Types.NUMERIC types,
this is the number of digits after the decimal point. For
Java Object types InputStream and Reader,
this is the length
of the data in the stream or reader. For all other types,
this value will be ignored.Sets the value of the designated parameter with the given object. |
| public default void | setObject(int
the first parameter is 1, the second is 2, ... parameterIndex, Object the object containing the input parameter value x, SQLType the SQL type to be sent to the database. The
scale argument may further qualify this type. targetSqlType, int for scaleOrLength)java.sql.JDBCType.DECIMAL
or java.sql.JDBCType.NUMERIC types,
this is the number of digits after the decimal point. For
Java Object types InputStream and Reader,
this is the length
of the data in the stream or reader. For all other types,
this value will be ignored.Sets the value of the designated parameter with the given object. |
| public default void | |
| public void | |
| public void | |
| public void | setShort(int
the first parameter is 1, the second is 2, ... parameterIndex, short the parameter value x)Sets the designated parameter to the given Java |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | setTimestamp(int
the first parameter is 1, the second is 2, ... parameterIndex, Timestamp the parameter value x)Sets the designated parameter to the given |
| public void | setTimestamp(int
the first parameter is 1, the second is 2, ... parameterIndex, Timestamp the parameter value x, Calendar the cal)Calendar object the driver will use
to construct the timestampSets the designated parameter to the given |
| public void | setUnicodeStream(int
the first parameter is 1, the second is 2, ... parameterIndex, InputStream a x, int java.io.InputStream object that contains the
Unicode parameter valuethe number of bytes in the stream length)
Deprecated
since 1.2. Use
setCharacterStream
Sets the designated parameter to the given input stream, which will have the specified number of bytes. |
| public void |