Package nl.cwi.monetdb.jdbc
Class MonetPreparedStatement
java.lang.Object
nl.cwi.monetdb.jdbc.MonetWrapper
nl.cwi.monetdb.jdbc.MonetStatement
nl.cwi.monetdb.jdbc.MonetPreparedStatement
- All Implemented Interfaces:
AutoCloseable,PreparedStatement,Statement,Wrapper
- Direct Known Subclasses:
MonetCallableStatement
public class MonetPreparedStatement extends MonetStatement implements PreparedStatement, AutoCloseable
A
PreparedStatement suitable for the MonetDB database.
This implementation of the PreparedStatement interface uses the
capabilities of the MonetDB/SQL backend to prepare and execute
statements. The backend takes care of finding the '?'s in the input and
returns the types it expects for them.
An example of a server response on a prepare query is:
% prepare select name from tables where id > ? and id < ?; &5 0 2 3 2 # prepare, prepare, prepare # table_name # type, digits, scale # name # varchar, int, int # type # 0, 0, 0 # length [ "int", 9, 0 ] [ "int", 9, 0 ]
- Version:
- 0.5v
- Author:
- Fabian Groffen, Martin van Dinther, Pedro Ferreira
-
Field Summary
Fields inherited from interface java.sql.Statement
CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO -
Method Summary
Modifier and Type Method Description voidaddBatch()Adds a set of parameters to this PreparedStatement object's batch of commands.voidaddBatch(String q)override the addBatch from the Statement to throw an SQLExceptionvoidclearParameters()Clears the current parameter values immediately.voidclose()Releases this PreparedStatement object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed.booleanexecute()Executes the SQL statement in this PreparedStatement object, which may be any kind of SQL statement.booleanexecute(String q)override the execute from the Statement to throw an SQLExceptionResultSetexecuteQuery()Executes the SQL query in this PreparedStatement object and returns the ResultSet object generated by the query.ResultSetexecuteQuery(String q)override the executeQuery from the Statement to throw an SQLExceptionintexecuteUpdate()Executes the SQL statement in this PreparedStatement object, which must be an SQL INSERT, UPDATE or DELETE statement; or an SQL statement that returns nothing, such as a DDL statement.intexecuteUpdate(String q)override the executeUpdate from the Statement to throw an SQLExceptionprotected voidfinalize()Call close to release the server-sided handle for this PreparedStatement.ResultSetMetaDatagetMetaData()Retrieves a ResultSetMetaData object that contains information about the columns of the ResultSet object that will be returned when this PreparedStatement object is executed.ParameterMetaDatagetParameterMetaData()Retrieves the number, types and properties of this PreparedStatement object's parameters.voidsetArray(int parameterIndex, Array x)Sets the designated parameter to the given Array object.voidsetAsciiStream(int parameterIndex, InputStream x)Sets the designated parameter to the given input stream, which will have the specified number of bytes.voidsetAsciiStream(int parameterIndex, InputStream x, int length)Sets the designated parameter to the given input stream, which will have the specified number of bytes.voidsetAsciiStream(int parameterIndex, InputStream x, long length)Sets the designated parameter to the given input stream, which will have the specified number of bytes.voidsetBigDecimal(int parameterIndex, BigDecimal x)Sets the designated parameter to the given java.math.BigDecimal value.voidsetBinaryStream(int parameterIndex, InputStream x)Sets the designated parameter to the given input stream, which will have the specified number of bytes.voidsetBinaryStream(int parameterIndex, InputStream x, int length)Sets the designated parameter to the given input stream, which will have the specified number of bytes.voidsetBinaryStream(int parameterIndex, InputStream x, long length)Sets the designated parameter to the given input stream, which will have the specified number of bytes.voidsetBlob(int parameterIndex, InputStream x)Sets the designated parameter to the given Blob object.voidsetBlob(int parameterIndex, InputStream is, long length)Sets the designated parameter to a InputStream object.voidsetBlob(int parameterIndex, Blob x)Sets the designated parameter to the given Blob object.voidsetBoolean(int parameterIndex, boolean x)Sets the designated parameter to the given Java boolean value.voidsetByte(int parameterIndex, byte x)Sets the designated parameter to the given Java byte value.voidsetBytes(int parameterIndex, byte[] x)Sets the designated parameter to the given Java array of bytes.voidsetCharacterStream(int parameterIndex, Reader reader)Sets the designated parameter to the given Reader object, which is the given number of characters long.voidsetCharacterStream(int parameterIndex, Reader reader, int length)Sets the designated parameter to the given Reader object, which is the given number of characters long.voidsetCharacterStream(int parameterIndex, Reader reader, long length)Sets the designated parameter to the given Reader object, which is the given number of characters long.voidsetClob(int parameterIndex, Reader reader)Sets the designated parameter to the given Clob object.voidsetClob(int parameterIndex, Reader reader, long length)Sets the designated parameter to a Reader object.voidsetClob(int parameterIndex, Clob x)Sets the designated parameter to the given Clob object.voidsetDate(int parameterIndex, Date x)Sets the designated parameter to the given java.sql.Date value.voidsetDate(int parameterIndex, Date x, Calendar cal)Sets the designated parameter to the given java.sql.Date value, using the given Calendar object.voidsetDouble(int parameterIndex, double x)Sets the designated parameter to the given Java double value.voidsetFloat(int parameterIndex, float x)Sets the designated parameter to the given Java float value.voidsetInt(int parameterIndex, int x)Sets the designated parameter to the given Java int value.voidsetLong(int parameterIndex, long x)Sets the designated parameter to the given Java long value.voidsetNCharacterStream(int parameterIndex, Reader value)Sets the designated parameter to a Reader object.voidsetNCharacterStream(int parameterIndex, Reader value, long length)Sets the designated parameter to a Reader object.voidsetNClob(int parameterIndex, Reader value)Sets the designated parameter to a java.sql.NClob object.voidsetNClob(int parameterIndex, Reader r, long length)Sets the designated parameter to a Reader object.voidsetNClob(int parameterIndex, NClob value)Sets the designated parameter to a java.sql.NClob object.voidsetNString(int parameterIndex, String value)Sets the designated paramter to the given String object.voidsetNull(int parameterIndex, int sqlType)Sets the designated parameter to SQL NULL.voidsetNull(int parameterIndex, int sqlType, String typeName)Sets the designated parameter to SQL NULL.voidsetObject(int parameterIndex, Object x)Sets the value of the designated parameter using the given object.voidsetObject(int parameterIndex, Object x, int targetSqlType)Sets the value of the designated parameter with the given object.voidsetObject(int parameterIndex, Object x, int targetSqlType, int scale)Sets the value of the designated parameter with the given object.voidsetRef(int parameterIndex, Ref x)Sets the designated parameter to the given REF(<structured-type>) value.voidsetRowId(int parameterIndex, RowId x)Sets the designated parameter to the given java.sql.RowId object.voidsetShort(int parameterIndex, short x)Sets the designated parameter to the given Java short value.voidsetSQLXML(int parameterIndex, SQLXML x)Sets the designated parameter to the given java.sql.SQLXML object.voidsetString(int parameterIndex, String x)Sets the designated parameter to the given Java String value.voidsetTime(int parameterIndex, Time x)Sets the designated parameter to the given java.sql.Time value.voidsetTime(int parameterIndex, Time x, Calendar cal)Sets the designated parameter to the given java.sql.Time value, using the given Calendar object.voidsetTimestamp(int parameterIndex, Timestamp x)Sets the designated parameter to the given java.sql.Timestamp value.voidsetTimestamp(int parameterIndex, Timestamp x, Calendar cal)Sets the designated parameter to the given java.sql.Timestamp value, using the given Calendar object.voidsetUnicodeStream(int parameterIndex, InputStream x, int length)Deprecated.voidsetURL(int parameterIndex, URL x)Sets the designated parameter to the given java.net.URL value.Methods inherited from class nl.cwi.monetdb.jdbc.MonetStatement
cancel, clearBatch, clearWarnings, closeOnCompletion, execute, execute, execute, executeBatch, executeUpdate, executeUpdate, executeUpdate, getConnection, getFetchDirection, getFetchSize, getGeneratedKeys, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getUpdateCount, getWarnings, internalBatch, isClosed, isCloseOnCompletion, isPoolable, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setMaxFieldSize, setMaxRows, setPoolable, setQueryTimeoutMethods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.sql.PreparedStatement
executeLargeUpdate, setObject, setObjectMethods inherited from interface java.sql.Statement
cancel, clearBatch, clearWarnings, closeOnCompletion, enquoteIdentifier, enquoteLiteral, enquoteNCharLiteral, execute, execute, execute, executeBatch, executeLargeBatch, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeUpdate, executeUpdate, executeUpdate, getConnection, getFetchDirection, getFetchSize, getGeneratedKeys, getLargeMaxRows, getLargeUpdateCount, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getUpdateCount, getWarnings, isClosed, isCloseOnCompletion, isPoolable, isSimpleIdentifier, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setLargeMaxRows, setMaxFieldSize, setMaxRows, setPoolable, setQueryTimeout
-
Method Details
-
addBatch
Adds a set of parameters to this PreparedStatement object's batch of commands.- Specified by:
addBatchin interfacePreparedStatement- Throws:
SQLException- if a database access error occurs
-
addBatch
override the addBatch from the Statement to throw an SQLException- Specified by:
addBatchin interfaceStatement- Overrides:
addBatchin classMonetStatement- Parameters:
q- typically this is a static SQL INSERT or UPDATE statement- Throws:
SQLException- so the PreparedStatement can throw this exception
-
clearParameters
public void clearParameters()Clears the current parameter values immediately. In general, parameter values remain in force for repeated use of a statement. Setting a parameter value automatically clears its previous value. However, in some cases it is useful to immediately release the resources used by the current parameter values; this can be done by calling the method clearParameters.- Specified by:
clearParametersin interfacePreparedStatement
-
execute
Executes the SQL statement in this PreparedStatement object, which may be any kind of SQL statement. Some prepared statements return multiple results; the execute method handles these complex statements as well as the simpler form of statements handled by the methods executeQuery and executeUpdate. The execute method returns a boolean to indicate the form of the first result. You must call either the method getResultSet or getUpdateCount to retrieve the result; you must call getMoreResults to move to any subsequent result(s).- Specified by:
executein interfacePreparedStatement- Returns:
- true if the first result is a ResultSet object; false if the first result is an update count or there is no result
- Throws:
SQLException- if a database access error occurs or an argument is supplied to this method
-
execute
override the execute from the Statement to throw an SQLException- Specified by:
executein interfaceStatement- Overrides:
executein classMonetStatement- Parameters:
q- any SQL statement- Returns:
- true if the first result is a ResultSet object; false if it is an update count or there are no results
- Throws:
SQLException- if a database access error occurs
-
executeQuery
Executes the SQL query in this PreparedStatement object and returns the ResultSet object generated by the query.- Specified by:
executeQueryin interfacePreparedStatement- Returns:
- a ResultSet object that contains the data produced by the query; never null
- Throws:
SQLException- if a database access error occurs or the SQL statement does not return a ResultSet object
-
executeQuery
override the executeQuery from the Statement to throw an SQLException- Specified by:
executeQueryin interfaceStatement- Overrides:
executeQueryin classMonetStatement- Parameters:
q- an SQL statement to be sent to the database, typically a static SQL SELECT statement- Returns:
- a ResultSet object that contains the data produced by the given query; never null
- Throws:
SQLException- if a database access error occurs or the given SQL statement produces anything other than a single ResultSet object
-
executeUpdate
Executes the SQL statement in this PreparedStatement object, which must be an SQL INSERT, UPDATE or DELETE statement; or an SQL statement that returns nothing, such as a DDL statement.- Specified by:
executeUpdatein interfacePreparedStatement- Returns:
- either (1) the row count for INSERT, UPDATE, or DELETE statements or (2) 0 for SQL statements that return nothing
- Throws:
SQLException- if a database access error occurs or the SQL statement returns a ResultSet object
-
executeUpdate
override the executeUpdate from the Statement to throw an SQLException- Specified by:
executeUpdatein interfaceStatement- Overrides:
executeUpdatein classMonetStatement- Parameters:
q- an SQL INSERT, UPDATE or DELETE statement or an SQL statement that returns nothing- Returns:
- either the row count for INSERT, UPDATE or DELETE statements, or 0 for SQL statements that return nothing
- Throws:
SQLException- if a database access error occurs or the given SQL statement produces a ResultSet object
-
getMetaData
Retrieves a ResultSetMetaData object that contains information about the columns of the ResultSet object that will be returned when this PreparedStatement object is executed. Because a PreparedStatement object is precompiled, it is possible to know about the ResultSet object that it will return without having to execute it. Consequently, it is possible to invoke the method getMetaData on a PreparedStatement object rather than waiting to execute it and then invoking the ResultSet.getMetaData method on the ResultSet object that is returned.- Specified by:
getMetaDatain interfacePreparedStatement- Returns:
- the description of a ResultSet object's columns or null if the driver cannot return a ResultSetMetaData object
- Throws:
SQLException- if a database access error occurs
-
getParameterMetaData
Retrieves the number, types and properties of this PreparedStatement object's parameters.- Specified by:
getParameterMetaDatain interfacePreparedStatement- Returns:
- a ParameterMetaData object that contains information about the number, types and properties of this PreparedStatement object's parameters
- Throws:
SQLException- if a database access error occurs
-
setArray
Sets the designated parameter to the given Array object. The driver converts this to an SQL ARRAY value when it sends it to the database.- Specified by:
setArrayin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- an Array object that maps an SQL ARRAY value- Throws:
SQLException- if a database access error occursSQLFeatureNotSupportedException- the JDBC driver does not support this method
-
setAsciiStream
Sets the designated parameter to the given input stream, which will have the specified number of bytes. When a very large ASCII value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.InputStream. Data will be read from the stream as needed until end-of-file is reached. The JDBC driver will do any necessary conversion from ASCII to the database char format. Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.- Specified by:
setAsciiStreamin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the Java input stream that contains the ASCII parameter value- Throws:
SQLException- if a database access error occursSQLFeatureNotSupportedException- the JDBC driver does not support this method
-
setAsciiStream
Sets the designated parameter to the given input stream, which will have the specified number of bytes. When a very large ASCII value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.InputStream. Data will be read from the stream as needed until end-of-file is reached. The JDBC driver will do any necessary conversion from ASCII to the database char format. Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.- Specified by:
setAsciiStreamin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the Java input stream that contains the ASCII parameter valuelength- the number of bytes in the stream- Throws:
SQLException- if a database access error occursSQLFeatureNotSupportedException- the JDBC driver does not support this method
-
setAsciiStream
Sets the designated parameter to the given input stream, which will have the specified number of bytes. When a very large ASCII value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.InputStream. Data will be read from the stream as needed until end-of-file is reached. The JDBC driver will do any necessary conversion from ASCII to the database char format. Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.- Specified by:
setAsciiStreamin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the Java input stream that contains the ASCII parameter valuelength- the number of bytes in the stream- Throws:
SQLException- if a database access error occursSQLFeatureNotSupportedException- the JDBC driver does not support this method
-
setBigDecimal
Sets the designated parameter to the given java.math.BigDecimal value. The driver converts this to an SQL NUMERIC value when it sends it to the database.- Specified by:
setBigDecimalin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setBinaryStream
Sets the designated parameter to the given input stream, which will have the specified number of bytes. When a very large binary value is input to a LONGVARBINARY parameter, it may be more practical to send it via a java.io.InputStream object. The data will be read from the stream as needed until end-of-file is reached. Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.- Specified by:
setBinaryStreamin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the java input stream which contains the binary parameter value- Throws:
SQLException- if a database access error occursSQLFeatureNotSupportedException- the JDBC driver does not support this method
-
setBinaryStream
Sets the designated parameter to the given input stream, which will have the specified number of bytes. When a very large binary value is input to a LONGVARBINARY parameter, it may be more practical to send it via a java.io.InputStream object. The data will be read from the stream as needed until end-of-file is reached. Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.- Specified by:
setBinaryStreamin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the java input stream which contains the binary parameter valuelength- the number of bytes in the stream- Throws:
SQLException- if a database access error occursSQLFeatureNotSupportedException- the JDBC driver does not support this method
-
setBinaryStream
Sets the designated parameter to the given input stream, which will have the specified number of bytes. When a very large binary value is input to a LONGVARBINARY parameter, it may be more practical to send it via a java.io.InputStream object. The data will be read from the stream as needed until end-of-file is reached. Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.- Specified by:
setBinaryStreamin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the java input stream which contains the binary parameter valuelength- the number of bytes in the stream- Throws:
SQLException- if a database access error occursSQLFeatureNotSupportedException- the JDBC driver does not support this method
-
setBlob
Sets the designated parameter to the given Blob object. The driver converts this to an SQL BLOB value when it sends it to the database.- Specified by:
setBlobin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- a Blob object that maps an SQL BLOB value- Throws:
SQLException- if a database access error occursSQLFeatureNotSupportedException- the JDBC driver does not support this method
-
setBlob
Sets the designated parameter to the given Blob object. The driver converts this to an SQL BLOB value when it sends it to the database.- Specified by:
setBlobin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- a Blob object that maps an SQL BLOB value- Throws:
SQLException- if a database access error occurs
-
setBlob
Sets the designated parameter to a InputStream object. The inputstream must contain the number of characters specified by length otherwise a SQLException will be generated when the PreparedStatement is executed. This method differs from the setBinaryStream (int, InputStream, int) method because it informs the driver that the parameter value should be sent to the server as a BLOB. When the setBinaryStream method is used, the driver may have to do extra work to determine whether the parameter data should be sent to the server as a LONGVARBINARY or a BLOB.- Specified by:
setBlobin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...is- an object that contains the data to set the parameter value tolength- the number of bytes in the parameter data- Throws:
SQLException- if a database access error occurs
-
setBoolean
Sets the designated parameter to the given Java boolean value. The driver converts this to an SQL BIT value when it sends it to the database.- Specified by:
setBooleanin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setByte
Sets the designated parameter to the given Java byte value. The driver converts this to an SQL TINYINT value when it sends it to the database.- Specified by:
setBytein interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setBytes
Sets the designated parameter to the given Java array of bytes. The driver converts this to an SQL VARBINARY or LONGVARBINARY (depending on the argument's size relative to the driver's limits on VARBINARY values) when it sends it to the database.- Specified by:
setBytesin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setCharacterStream
Sets the designated parameter to the given Reader object, which is the given number of characters long. When a very large UNICODE value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.Reader object. The data will be read from the stream as needed until end-of-file is reached. The JDBC driver will do any necessary conversion from UNICODE to the database char format. Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.- Specified by:
setCharacterStreamin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...reader- the java.io.Reader object that contains the Unicode datalength- the number of characters in the stream- Throws:
SQLException- if a database access error occurs
-
setCharacterStream
Sets the designated parameter to the given Reader object, which is the given number of characters long. When a very large UNICODE value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.Reader object. The data will be read from the stream as needed until end-of-file is reached. The JDBC driver will do any necessary conversion from UNICODE to the database char format. Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.- Specified by:
setCharacterStreamin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...reader- the java.io.Reader object that contains the Unicode data- Throws:
SQLException- if a database access error occurs
-
setCharacterStream
Sets the designated parameter to the given Reader object, which is the given number of characters long. When a very large UNICODE value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.Reader object. The data will be read from the stream as needed until end-of-file is reached. The JDBC driver will do any necessary conversion from UNICODE to the database char format. Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.- Specified by:
setCharacterStreamin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...reader- the java.io.Reader object that contains the Unicode datalength- the number of characters in the stream- Throws:
SQLException- if a database access error occurs
-
setClob
Sets the designated parameter to the given Clob object. The driver converts this to an SQL CLOB value when it sends it to the database.- Specified by:
setClobin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- a Clob object that maps an SQL CLOB value- Throws:
SQLException- if a database access error occurs
-
setClob
Sets the designated parameter to the given Clob object. The driver converts this to an SQL CLOB value when it sends it to the database.- Specified by:
setClobin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...reader- an object that contains the data to set the parameter value to- Throws:
SQLException- if a database access error occurs
-
setClob
Sets the designated parameter to a Reader object. The reader must contain the number of characters specified by length otherwise a SQLException will be generated when the PreparedStatement is executed. This method differs from the setCharacterStream (int, Reader, int) method because it informs the driver that the parameter value should be sent to the server as a CLOB. When the setCharacterStream method is used, the driver may have to do extra work to determine whether the parameter data should be sent to the server as a LONGVARCHAR or a CLOB.- Specified by:
setClobin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...reader- An object that contains the data to set the parameter value to.length- the number of characters in the parameter data.- Throws:
SQLException- if a database access error occurs
-
setDate
Sets the designated parameter to the given java.sql.Date value. The driver converts this to an SQL DATE value when it sends it to the database.- Specified by:
setDatein interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setDate
Sets the designated parameter to the given java.sql.Date value, using the given Calendar object. The driver uses the Calendar object to construct an SQL DATE value, which the driver then sends to the database. With a Calendar object, the driver can calculate the date taking into account a custom timezone. If no Calendar object is specified, the driver uses the default timezone, which is that of the virtual machine running the application.- Specified by:
setDatein interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter valuecal- the Calendar object the driver will use to construct the date- Throws:
SQLException- if a database access error occurs
-
setDouble
Sets the designated parameter to the given Java double value. The driver converts this to an SQL DOUBLE value when it sends it to the database.- Specified by:
setDoublein interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setFloat
Sets the designated parameter to the given Java float value. The driver converts this to an SQL FLOAT value when it sends it to the database.- Specified by:
setFloatin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setInt
Sets the designated parameter to the given Java int value. The driver converts this to an SQL INTEGER value when it sends it to the database.- Specified by:
setIntin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setLong
Sets the designated parameter to the given Java long value. The driver converts this to an SQL BIGINT value when it sends it to the database.- Specified by:
setLongin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setNCharacterStream
Sets the designated parameter to a Reader object. The Reader reads the data till end-of-file is reached. The driver does the necessary conversion from Java character format to the national character set in the database.- Specified by:
setNCharacterStreamin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...value- the parameter value- Throws:
SQLException- if a database access error occurs
-
setNCharacterStream
Sets the designated parameter to a Reader object. The Reader reads the data till end-of-file is reached. The driver does the necessary conversion from Java character format to the national character set in the database.- Specified by:
setNCharacterStreamin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...value- the parameter valuelength- the number of characters in the parameter data.- Throws:
SQLException- if a database access error occurs
-
setNClob
Sets the designated parameter to a java.sql.NClob object. The driver converts this to a SQL NCLOB value when it sends it to the database.- Specified by:
setNClobin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...value- the parameter value- Throws:
SQLException- if a database access error occursSQLFeatureNotSupportedException- the JDBC driver does not support this method
-
setNClob
Sets the designated parameter to a java.sql.NClob object. The driver converts this to a SQL NCLOB value when it sends it to the database.- Specified by:
setNClobin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...value- the parameter value- Throws:
SQLException- if a database access error occursSQLFeatureNotSupportedException- the JDBC driver does not support this method
-
setNClob
Sets the designated parameter to a Reader object. The reader must contain the number of characters specified by length otherwise a SQLException will be generated when the PreparedStatement is executed. This method differs from the setCharacterStream (int, Reader, int) method because it informs the driver that the parameter value should be sent to the server as a NCLOB. When the setCharacterStream method is used, the driver may have to do extra work to determine whether the parameter data should be sent to the server as a LONGNVARCHAR or a NCLOB.- Specified by:
setNClobin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...r- An object that contains the data to set the parameter value tolength- the number of characters in the parameter data- Throws:
SQLException- if a database access error occursSQLFeatureNotSupportedException- the JDBC driver does not support this method
-
setNString
Sets the designated paramter to the given String object. The driver converts this to a SQL NCHAR or NVARCHAR or LONGNVARCHAR value (depending on the argument's size relative to the driver's limits on NVARCHAR values) when it sends it to the database.- Specified by:
setNStringin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...value- the parameter value- Throws:
SQLException- if a database access error occurs
-
setNull
Sets the designated parameter to SQL NULL. Note: You must specify the parameter's SQL type.- Specified by:
setNullin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...sqlType- the SQL type code defined in java.sql.Types- Throws:
SQLException- if a database access error occurs
-
setNull
Sets the designated parameter to SQL NULL. This version of the method setNull should be used for user-defined types and REF type parameters. Examples of user-defined types include: STRUCT, DISTINCT, JAVA_OBJECT, and named array types. Note: To be portable, applications must give the SQL type code and the fully-qualified SQL type name when specifying a NULL user-defined or REF parameter. In the case of a user-defined type the name is the type name of the parameter itself. For a REF parameter, the name is the type name of the referenced type. If a JDBC driver does not need the type code or type name information, it may ignore it. Although it is intended for user-defined and Ref parameters, this method may be used to set a null parameter of any JDBC type. If the parameter does not have a user-defined or REF type, the given typeName is ignored.- Specified by:
setNullin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...sqlType- a value from java.sql.TypestypeName- the fully-qualified name of an SQL user-defined type; ignored if the parameter is not a user-defined type or REF- Throws:
SQLException- if a database access error occurs
-
setObject
Sets the value of the designated parameter using the given object. The second parameter must be of type Object; therefore, the java.lang equivalent objects should be used for built-in types. The JDBC specification specifies a standard mapping from Java Object types to SQL types. The given argument will be converted to the corresponding SQL type before being sent to the database. Note that this method may be used to pass datatabase-specific abstract data types, by using a driver-specific Java type. If the object is of a class implementing the interface SQLData, the JDBC driver should call the method SQLData.writeSQL to write it to the SQL data stream. If, on the other hand, the object is of a class implementing Ref, Blob, Clob, Struct, or Array, the driver should pass it to the database as a value of the corresponding SQL type. This method throws an exception if there is an ambiguity, for example, if the object is of a class implementing more than one of the interfaces named above.- Specified by:
setObjectin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the object containing the input parameter value- Throws:
SQLException- if a database access error occurs or the type of the given object is ambiguous
-
setObject
Sets the value of the designated parameter with the given object. This method is like the method setObject below, except that it assumes a scale of zero.- Specified by:
setObjectin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the object containing the input parameter valuetargetSqlType- the SQL type (as defined in java.sql.Types) to be sent to the database- Throws:
SQLException- if a database access error occurs
-
setObject
public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLExceptionSets the value of the designated parameter with the given object. The second argument must be an object type; for integral values, the java.lang equivalent objects should be used. The given Java object will be converted to the given targetSqlType before being sent to the database. If the object has a custom mapping (is of a class implementing the interface SQLData), the JDBC driver should call the method SQLData.writeSQL to write it to the SQL data stream. If, on the other hand, the object is of a class implementing Ref, Blob, Clob, Struct, or Array, the driver should pass it to the database as a value of the corresponding SQL type. Note that this method may be used to pass database-specific abstract data types. To meet the requirements of this interface, the Java object is converted in the driver, instead of using a SQL CAST construct.- Specified by:
setObjectin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the object containing the input parameter valuetargetSqlType- the SQL type (as defined in java.sql.Types) to be sent to the database. The scale argument may further qualify this type.scale- for 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.- Throws:
SQLException- if a database access error occursSQLFeatureNotSupportedException- the JDBC driver does not support this method- See Also:
Types
-
setRef
Sets the designated parameter to the given REF(<structured-type>) value. The driver converts this to an SQL REF value when it sends it to the database.- Specified by:
setRefin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- an SQL REF value- Throws:
SQLException- if a database access error occursSQLFeatureNotSupportedException- the JDBC driver does not support this method
-
setRowId
Sets the designated parameter to the given java.sql.RowId object. The driver converts this to a SQL ROWID value when it sends it to the database.- Specified by:
setRowIdin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- if a database access error occursSQLFeatureNotSupportedException- the JDBC driver does not support this method
-
setShort
Sets the designated parameter to the given Java short value. The driver converts this to an SQL SMALLINT value when it sends it to the database.- Specified by:
setShortin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setString
Sets the designated parameter to the given Java String value. The driver converts this to an SQL VARCHAR or LONGVARCHAR value (depending on the argument's size relative to the driver's limits on VARCHAR values) when it sends it to the database.- Specified by:
setStringin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setSQLXML
Sets the designated parameter to the given java.sql.SQLXML object. The driver converts this to an SQL XML value when it sends it to the database.- Specified by:
setSQLXMLin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- a SQLXML object that maps an SQL XML value- Throws:
SQLException- if a database access error occursSQLFeatureNotSupportedException- the JDBC driver does not support this method
-
setTime
Sets the designated parameter to the given java.sql.Time value. The driver converts this to an SQL TIME value when it sends it to the database.- Specified by:
setTimein interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setTime
Sets the designated parameter to the given java.sql.Time value, using the given Calendar object. The driver uses the Calendar object to construct an SQL TIME value, which the driver then sends to the database. With a Calendar object, the driver can calculate the time taking into account a custom timezone. If no Calendar object is specified, the driver uses the default timezone, which is that of the virtual machine running the application.- Specified by:
setTimein interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter valuecal- the Calendar object the driver will use to construct the time- Throws:
SQLException- if a database access error occurs
-
setTimestamp
Sets the designated parameter to the given java.sql.Timestamp value. The driver converts this to an SQL TIMESTAMP value when it sends it to the database.- Specified by:
setTimestampin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setTimestamp
Sets the designated parameter to the given java.sql.Timestamp value, using the given Calendar object. The driver uses the Calendar object to construct an SQL TIMESTAMP value, which the driver then sends to the database. With a Calendar object, the driver can calculate the timestamp taking into account a custom timezone. If no Calendar object is specified, the driver uses the default timezone, which is that of the virtual machine running the application.- Specified by:
setTimestampin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter valuecal- the Calendar object the driver will use to construct the timestamp- Throws:
SQLException- if a database access error occurs
-
setUnicodeStream
@Deprecated public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLExceptionDeprecated.Sets the designated parameter to the given input stream, which will have the specified number of bytes. A Unicode character has two bytes, with the first byte being the high byte, and the second being the low byte. When a very large Unicode value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.InputStream object. The data will be read from the stream as needed until end-of-file is reached. The JDBC driver will do any necessary conversion from Unicode to the database char format. Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.- Specified by:
setUnicodeStreamin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- a java.io.InputStream object that contains the Unicode parameter value as two-byte Unicode characterslength- the number of bytes in the stream- Throws:
SQLException- if a database access error occursSQLFeatureNotSupportedException- the JDBC driver does not support this method
-
setURL
Sets the designated parameter to the given java.net.URL value. The driver converts this to an SQL DATALINK value when it sends it to the database.- Specified by:
setURLin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the java.net.URL object to be set- Throws:
SQLException- if a database access error occurs
-
close
public void close()Releases this PreparedStatement object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed. It is generally good practice to release resources as soon as you are finished with them to avoid tying up database resources. Calling the method close on a PreparedStatement object that is already closed has no effect. Note: A PreparedStatement object is automatically closed when it is garbage collected. When a Statement object is closed, its current ResultSet object, if one exists, is also closed.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceStatement- Overrides:
closein classMonetStatement
-
finalize
protected void finalize()Call close to release the server-sided handle for this PreparedStatement.
-