Interface PreparedStatement

public interface PreparedStatement extends Object extends Statement

SQL statements can be precompiled by the database and executed with different parameters as many times as you want. setXXX methods are used to set IN param-eter values. They must specify types compatible with the defined SQL type of the input parameter. Arbitrary parameter type conversions are allowed, but then you should use the setObject method with a SQL type to specify the target type.

See also: prepareStatement, ResultSet

Methods

addBatch

public void addBatch() throws SQLException

This method adds a set of parameters to the PreparedStatement’s batch of SQL commands.

clearParameters

public void clearParameters() throws SQLException

clearParameters() immediately releases the resources used by the current param-eter values. Parameter values aren’t automatically cleared after the execution of a PreparedStatement, so they can be used for repeated use.

Returns: Nothing

execute

public boolean execute() throws SQLException

This method executes the statement with the IN parameter values just set, if any. Note that execute is normally used for prepared statements that return multiple results.

Returns: true if the next result is a ResultSet; false if it is an update count or there is no more result

See also: execute

executeQuery

public ResultSet executeQuery() throws SQLException

executeQuery() is used to execute prepared SQL queries (SELECT only). It returns a ResultSet.

Returns: A ResultSet that contains the data produced by the query; never null

executeUpdate

public int executeUpdate() throws SQLException

executeUpdate is used to execute a SQL INSERT, UPDATE, or DELETE statement. It also supports SQL statements that return nothing, such as SQL DDL.

Returns: The number of rows affected for INSERT, UPDATE, or DELETE or 0 for SQL statements that return nothing

getMetaData

public ResultSetMetaData getMetaData() throws SQLException 

This gets the number, types, and properties of a ResultSet’s columns.

Returns: The metadata of a ResultSet

getParameterMetaData

public ParameterMetaData getParameterMetaData() throws SQLException

This gets the number, types, and properties of a PreparedStatement object’s parameters.

Returns: The ParameterMetaData object that contains information about the number, types, and properties of the PreparedStatement parameters

setArray

public void setArray(int parameterIndex, Array x) throws SQLException

This sets the parameter to the given Array object.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The Array object that maps a SQL ARRAY value.

setAsciiStream

public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException

setAsciiStream() is used to set very large LONGVARCHAR parameters. You can send the ASCII data using a java.io.inputStream. JDBC stops sending data when it reaches EOF (end of file). ASCII characters are converted to the database CHAR format.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The ASCII data stream.

length:

The data length in bytes.

setBigDecimal

public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException

This supplies a java.math.BigDecimal value that will be converted to a SQL NUMERIC value when sent to the database.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The parameter value.

setBinaryStream

public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException

setBinaryStream() is used to set very large LONGVARBINARY parameters. You can send the binary data using a java.io.inputStream. JDBC stops sending data when it reaches EOF (end of file).

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The binary data stream.

length:

The data length in bytes.

setBlob

public void setBlob(int parameterIndex, Blob x) throws SQLException

This sets the parameter to the given Blob object.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

A Blob object that maps a SQL BLOB value

setBoolean

public void setBoolean(int parameterIndex, boolean x) throws SQLException

This supplies a Java boolean value that is converted to a SQL BIT value when sent to the database.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The parameter value.

setByte

public void setByte(int parameterIndex, byte x) throws SQLException

This supplies a Java byte value that is converted to a SQL TINYINT value when sent to the database.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The parameter value.

setBytes

public void setBytes(int parameterIndex, byte x[]) throws SQLException

This supplies a Java array of bytes that is converted to a SQL VARBINARY or LONGVARBINARY when sent to the database.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The parameter value.

setCharacterStream

public void setCharacterStream(int parameterIndex, java.io.Reader reader, int length) throws SQLException

This sets a Unicode character stream to the designated parameter.

Parameters:

parameterIndex:

The parameter index begins at 1.

reader:

The java.io.Reader object containing the Unicode data.

length:

The number of characters in the stream.

setClob

public void setClob(int parameterIndex, Clob x) throws SQLException

This sets the parameter to the given Clob object.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The Clob object that maps a SQL CLOB value.

setDate

public void setDate(int parameterIndex, Date x) throws SQLException

This supplies a java.sql.Date value that is converted to a SQL DATE value when sent to the database.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The parameter value.

setDate

public void setDate(int parameterIndex, Date x, java.util.Calendar cal) throws SQLException 

This supplies a java.sql.Date value that is converted to a SQL DATE value when sent to the database using the Calendar object provided as a parameter.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The parameter value.

cal:

The Calendar object the driver will use to construct the date.

setDouble

public void setDouble(int parameterIndex, double x) throws SQLException

This supplies a Java double value that is converted to a SQL DOUBLE value when sent to the database.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The parameter value.

setFloat

public void setFloat(int parameterIndex, float x) throws SQLException

This supplies a Java float value that is converted to a SQL FLOAT value when sent to the database.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The parameter value.

setInt

public void setInt(int parameterIndex, int x) throws SQLException

This supplies a Java int value that is converted to a SQL INTEGER value when sent to the database.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The parameter value.

setLong

public void setLong(int parameterIndex, long x) throws SQLException 

This supplies a Java long value that is converted to a SQL BIGINT value when sent to the database.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The parameter value.

setNull

public void setNull(int parameterIndex, int sqlType) throws SQLException

This supplies a SQL NULL value. The parameter’s SQL type must be supplied.

Parameters:

parameterIndex:

The parameter index begins at 1.

sqlType:

A SQL type code (see java.sql.Types).

setNull

public void setNull(int paramIndex, int sqlType, String typeName) throws SQLException

This supplies a SQL NULL value. The parameter’s SQL type must be supplied as well as the fully qualified SQL Type name for greater portability.

Parameters:

paramIndex:

The parameter index begins at 1.

sqlType:

A value from java.sql.Types.

typeName:

The fully qualified name of a SQL user-defined type. It is ignored if the parameter isn’t a user-defined type or REF type.

setObject

public void setObject(int parameterIndex, Object x,int targetSqlType, int scale) throws SQLException

This supplies a parameter value using an object that is converted to the targetSqlType when sent to the database. Data types can be passed using a driver-specific Java type and using java.sql.types.OTHER as targetSqlType.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The object containing the input parameter value.

targetSqlType:

A SQL type code (see java.sql.Types).

scale:

The number of digits after the decimal for

java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types. Ignored for other types

See also: Types

setObject

public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException

This is the same as setObject(int parameterIndex, Object x,int targetSqlType, int scale) but assumes a scale of zero.

setObject

public void setObject(int parameterIndex, Object x) throws SQLException

This is the same as setObject(int parameterIndex, Object x,int targetSqlType, int scale) but uses the standard mapping from Java Object types to SQL types.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The object containing the input parameter value.

setRef

public void setRef(int parameterIndex, Ref x) throws SQLException

This sets the parameter to the given REF value.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

A SQL REF value.

setShort

public void setShort(int parameterIndex, short x) throws SQLException

This supplies a Java short value that is converted to a SQL SMALLINT value when sent to the database.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The parameter value.

setString

public void setString(int parameterIndex, String x) throws SQLException

This supplies a Java String value that is converted to a SQL VARCHAR or LONGVARCHAR value when sent to the database.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The parameter value.

setTime

public void setTime(int parameterIndex, Time x) throws SQLException

This supplies a java.sql.Time value that is converted to a SQL TIME value when sent to the database.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The parameter value.

setTime

public void setTime(int parameterIndex, Time x, java.util.Calendar cal) throws SQLException

This supplies a java.sql.Time value that is converted to a SQL TIME value when sent to the database using the Calendar object provided as a parameter.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The parameter value.

cal:

The Calendar object the driver will use to construct the time.

setTimestamp

public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException

This supplies a java.sql.Timestamp value that is converted to a SQL TIMESTAMP value when sent to the database.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The parameter value.

setTimestamp

public void setTimestamp(int parameterIndex, Timestamp x, java.util.Calendar cal) throws SQLException

This supplies a java.sql.Timestamp value that is converted to a SQL TIMESTAMP value when sent to the database using the Calendar object provided as a parameter.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The parameter value.

cal:

The Calendar object the driver will use to construct the timestamp.

setUnicodeStream

public void setUnicodeStream(int parameterIndex, InputStream x,int length) throws SQLException

setUnicodeStream() is used to set very large LONGVARCHAR parameters. You can send the Unicode data using a java.io.inputStream. JDBC stops sending data when it reaches EOF (end of file). Unicode characters are converted to the database CHAR format.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The unicode data stream.

length:

The data length in bytes.

setURL

public void setURL(int parameterIndex, java.net.URL x) throws SQLException

This sets the parameter to a java.net.URL value. This value is converted to a SQL DATALINK when sent to the database.

Parameters:

parameterIndex:

The parameter index begins at 1.

x:

The parameter value.



JDBC 3. 0. JAVA Database Connectivity
JDBC 3: Java Database Connectivity
ISBN: 0764548751
EAN: 2147483647
Year: 2002
Pages: 148

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net