org.objectweb.cjdbc.driver
Class PreparedStatement

java.lang.Object
  extended byorg.objectweb.cjdbc.driver.Statement
      extended byorg.objectweb.cjdbc.driver.PreparedStatement
All Implemented Interfaces:
java.sql.PreparedStatement, java.sql.Statement
Direct Known Subclasses:
CallableStatement

public class PreparedStatement
extends Statement
implements java.sql.PreparedStatement

A SQL Statement is pre-compiled and stored in a PreparedStatement object. This object can then be used to efficiently execute this statement multiple times.

Note: The setXXX methods 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 setInt should be used.

If arbitrary parameter type conversions are required, then the setObject method should be used with a target SQL type.

In the old days, this was just a dirty copy/paste from the PostgreSQL driver. Some irrelevant comments are left-over here and there.

This class could maybe be splitted into DriverProcessedPreparedStatement and ProxyModeProcessedStatement

Version:
1.0
Author:
Emmanuel Cecchet , Nicolas Modrzyk , Marc Wick , Jaco Swart
See Also:
DriverResultSet, PreparedStatement

Nested Class Summary
private  class PreparedStatement.BatchElement
          This class defines a BatchElement used for the batch update vector of PreparedStatements to execute.
 
Field Summary
static java.lang.String BIG_DECIMAL_TAG
          Tag for a big decimal parameter
static java.lang.String BLOB_TAG
          Tag for a BLOB (used for null Blob) parameter
static java.lang.String BOOLEAN_TAG
          Tag for a boolean parameter
static java.lang.String BYTE_TAG
          Tag for a byte parameter
static java.lang.String BYTES_TAG
          Tag for a bytes (used for Blob) parameter
static java.lang.String CLOB_TAG
          Tag for a CLOB (used for null Clob) parameter
static java.lang.String DATE_TAG
          Tag for a date parameter
static java.lang.String DOUBLE_TAG
          Tag for a double parameter
static java.lang.String END_PARAM_TAG
          Tag for parameters end delimiter
static java.lang.String FLOAT_TAG
          Tag for a float parameter
private  java.lang.String[] inStrings
          IN parameters, ready to be inlined in the request
static java.lang.String INTEGER_TAG
          Tag for a integer parameter
static java.lang.String LONG_TAG
          Tag for a long parameter
static java.lang.String NULL_STRING_TAG
          Tag for a Null string parameter
static java.lang.String NULL_TAG
          Tag for a setNull call
static java.lang.String OBJECT_TAG
          Tag for an object parameter
static java.lang.String REF_TAG
          Tag for a Ref parameter
private  java.lang.StringBuffer sbuf
           
static java.lang.String SHORT_TAG
          Tag for a short parameter
protected  java.lang.String sql
          original, untouched request (only trimmed)
static java.lang.String START_PARAM_TAG
          Tag for parameters start delimiter
static java.lang.String STRING_TAG
          Tag for a string parameter
static java.lang.String TAG_MARKER
          Tag maker for parameters
static java.lang.String TAG_MARKER_ESCAPE
          Escape for tag maker
private  java.lang.String[] templateStrings
          segments: the request splitted by question marks placeholders
static java.lang.String TIME_TAG
          Tag for a time parameter
static java.lang.String TIMESTAMP_TAG
          Tag for a timestamp parameter
static java.lang.String URL_TAG
          Tag for an URL parameter
 
Fields inherited from class org.objectweb.cjdbc.driver.Statement
batch, connection, escapeProcessing, generatedKeys, generatedKeysFlag, result, updateCount
 
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
 
Constructor Summary
PreparedStatement(Connection connection, java.lang.String sqlStatement)
          Constructor.
 
Method Summary
 void addBatch()
          This parses the query and adds it to the current batch
 void clearParameters()
          In general, parameter values remain in force for repeated used of a Statement.
 void close()
          Release objects for garbage collection and call Statement.close().
protected  java.lang.String compileQuery()
          Helper - this compiles the SQL query, inlining the parameters in the request String.
protected  java.lang.String doEscapeProcessing(java.lang.String x)
          Escape the input string.
 boolean execute()
          Some prepared statements return multiple results; the execute method handles these complex statements as well as the simpler form of statements handled by executeQuery() and executeUpdate().
 int[] executeBatch()
          Execute a batch of commands
 java.sql.ResultSet executeQuery()
          A Prepared SQL query is executed and its ResultSet is returned.
 int executeUpdate()
          Execute a SQL INSERT, UPDATE or DELETE statement.
 java.sql.ResultSetMetaData getMetaData()
          Returns the MetaData for the last ResultSet returned.
 java.sql.ParameterMetaData getParameterMetaData()
          Retrieves the number, types and properties of this PreparedStatement object's parameters.
private  void set(int paramIndex, java.lang.String s)
          Actually stores the IN parameter into parameters String array.
 void setArray(int i, java.sql.Array x)
           
 void setAsciiStream(int parameterIndex, java.io.InputStream x, int length)
          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.
 void setBigDecimal(int parameterIndex, java.math.BigDecimal x)
          Sets a parameter to a java.lang.BigDecimal value.
 void setBinaryStream(int parameterIndex, java.io.InputStream inStreamArg, int length)
          Stores a binary stream into parameters array, using an intermediate byte[].
 void setBlob(int paramIndex, java.sql.Blob sqlBlobParam)
           
 void setBoolean(int parameterIndex, boolean x)
          Sets a parameter to a Java boolean value.
 void setByte(int parameterIndex, byte x)
          Sets a parameter to a Java byte value.
 void setBytes(int parameterIndex, byte[] x)
          Sets a parameter to a Java array of bytes.
 void setCharacterStream(int i, java.io.Reader x, int length)
           
 void setClob(int i, java.sql.Clob clobArg)
           
 void setDate(int parameterIndex, java.sql.Date x)
          Sets a parameter to a java.sql.Date value.
 void setDate(int i, java.sql.Date d, java.util.Calendar cal)
           
 void setDouble(int parameterIndex, double x)
          Sets a parameter to a Java double value.
 void setFloat(int parameterIndex, float x)
          Sets a parameter to a Java float value.
protected  void setGeneratedKeysFlag(int autoGeneratedKeys)
          Set the auto generated key flag defined in Statement
 void setInt(int parameterIndex, int x)
          Sets a parameter to a Java int value.
 void setLong(int parameterIndex, long x)
          Sets a parameter to a Java long value.
 void setNull(int parameterIndex, int sqlType)
          Sets a parameter to SQL NULL.
 void setNull(int i, int t, java.lang.String s)
           
 void setObject(int parameterIndex, java.lang.Object x)
          This stores an Object parameter into the parameters array.
 void setObject(int parameterIndex, java.lang.Object x, int targetSqlType)
           
 void setObject(int parameterIndex, java.lang.Object x, int targetSqlType, int scale)
          Sets the value of a parameter using an object; use the java.lang equivalent objects for integral values.
static void setPreparedStatement(java.lang.String quotedRequest, java.sql.PreparedStatement backendPS)
          Static method to initialize a backend PreparedStatement by calling the appropriate setXXX methods on the request skeleton.
 void setRef(int i, java.sql.Ref x)
           
 void setShort(int parameterIndex, short x)
          Sets a parameter to a Java short value.
 void setString(int parameterIndex, java.lang.String x)
          Sets a parameter to a Java String value.
 void setTime(int parameterIndex, java.sql.Time x)
          Sets a parameter to a java.sql.Time value.
 void setTime(int i, java.sql.Time t, java.util.Calendar cal)
           
 void setTimestamp(int parameterIndex, java.sql.Timestamp x)
          Sets a parameter to a java.sql.Timestamp value.
 void setTimestamp(int i, java.sql.Timestamp t, java.util.Calendar cal)
           
 void setUnicodeStream(int parameterIndex, java.io.InputStream x, int length)
          Deprecated.  
 void setURL(int parameterIndex, java.net.URL x)
          Sets the designated parameter to the given java.net.URL value.
private  void setWithTag(int paramIndex, java.lang.String typeTag, java.lang.String param)
          Stores parameter and its type as a quoted String, so the controller can decode them back.
 java.lang.String toString()
          Returns the SQL statement with the current template values substituted.
 
Methods inherited from class org.objectweb.cjdbc.driver.Statement
addBatch, cancel, clearBatch, clearWarnings, execute, execute, execute, execute, executeQuery, executeQuery, executeUpdate, executeUpdate, executeUpdate, executeUpdate, executeUpdateWithSkeleton, getConnection, getFetchDirection, getFetchSize, getGeneratedKeys, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getUpdateCount, getWarnings, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setMaxFieldSize, setMaxRows, setQueryTimeout, setResultSetConcurrency, setResultSetType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.sql.Statement
addBatch, cancel, clearBatch, clearWarnings, execute, execute, execute, execute, executeQuery, executeUpdate, executeUpdate, executeUpdate, executeUpdate, getConnection, getFetchDirection, getFetchSize, getGeneratedKeys, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getUpdateCount, getWarnings, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setMaxFieldSize, setMaxRows, setQueryTimeout
 

Field Detail

BYTE_TAG

public static final java.lang.String BYTE_TAG
Tag for a byte parameter

See Also:
Constant Field Values

BYTES_TAG

public static final java.lang.String BYTES_TAG
Tag for a bytes (used for Blob) parameter

See Also:
Constant Field Values

BLOB_TAG

public static final java.lang.String BLOB_TAG
Tag for a BLOB (used for null Blob) parameter

See Also:
Constant Field Values

CLOB_TAG

public static final java.lang.String CLOB_TAG
Tag for a CLOB (used for null Clob) parameter

See Also:
Constant Field Values

BOOLEAN_TAG

public static final java.lang.String BOOLEAN_TAG
Tag for a boolean parameter

See Also:
Constant Field Values

BIG_DECIMAL_TAG

public static final java.lang.String BIG_DECIMAL_TAG
Tag for a big decimal parameter

See Also:
Constant Field Values

DATE_TAG

public static final java.lang.String DATE_TAG
Tag for a date parameter

See Also:
Constant Field Values

DOUBLE_TAG

public static final java.lang.String DOUBLE_TAG
Tag for a double parameter

See Also:
Constant Field Values

FLOAT_TAG

public static final java.lang.String FLOAT_TAG
Tag for a float parameter

See Also:
Constant Field Values

INTEGER_TAG

public static final java.lang.String INTEGER_TAG
Tag for a integer parameter

See Also:
Constant Field Values

LONG_TAG

public static final java.lang.String LONG_TAG
Tag for a long parameter

See Also:
Constant Field Values

NULL_TAG

public static final java.lang.String NULL_TAG
Tag for a setNull call

See Also:
Constant Field Values

NULL_STRING_TAG

public static final java.lang.String NULL_STRING_TAG
Tag for a Null string parameter

See Also:
Constant Field Values

OBJECT_TAG

public static final java.lang.String OBJECT_TAG
Tag for an object parameter

See Also:
Constant Field Values

REF_TAG

public static final java.lang.String REF_TAG
Tag for a Ref parameter

See Also:
Constant Field Values

SHORT_TAG

public static final java.lang.String SHORT_TAG
Tag for a short parameter

See Also:
Constant Field Values

STRING_TAG

public static final java.lang.String STRING_TAG
Tag for a string parameter

See Also:
Constant Field Values

TIME_TAG

public static final java.lang.String TIME_TAG
Tag for a time parameter

See Also:
Constant Field Values

TIMESTAMP_TAG

public static final java.lang.String TIMESTAMP_TAG
Tag for a timestamp parameter

See Also:
Constant Field Values

URL_TAG

public static final java.lang.String URL_TAG
Tag for an URL parameter

See Also:
Constant Field Values

TAG_MARKER

public static final java.lang.String TAG_MARKER
Tag maker for parameters

See Also:
Constant Field Values

TAG_MARKER_ESCAPE

public static final java.lang.String TAG_MARKER_ESCAPE
Escape for tag maker

See Also:
Constant Field Values

START_PARAM_TAG

public static final java.lang.String START_PARAM_TAG
Tag for parameters start delimiter

See Also:
Constant Field Values

END_PARAM_TAG

public static final java.lang.String END_PARAM_TAG
Tag for parameters end delimiter

See Also:
Constant Field Values

sql

protected java.lang.String sql
original, untouched request (only trimmed)


inStrings

private java.lang.String[] inStrings
IN parameters, ready to be inlined in the request


templateStrings

private java.lang.String[] templateStrings
segments: the request splitted by question marks placeholders


sbuf

private java.lang.StringBuffer sbuf
Constructor Detail

PreparedStatement

public PreparedStatement(Connection connection,
                         java.lang.String sqlStatement)
                  throws java.sql.SQLException
Constructor. Parses/Splits the SQL statement into segments - string parts separated by question mark placeholders. When we rebuild the thing with the arguments, we can substitute the args by joining segments and parameters back together.

Parameters:
connection - the instanatiating connection
sqlStatement - the SQL statement with ? for IN markers
Throws:
java.sql.SQLException - if something bad occurs
Method Detail

close

public void close()
           throws java.sql.SQLException
Release objects for garbage collection and call Statement.close().

Specified by:
close in interface java.sql.Statement
Overrides:
close in class Statement
Throws:
java.sql.SQLException - if an error occurs

executeQuery

public java.sql.ResultSet executeQuery()
                                throws java.sql.SQLException
A Prepared SQL query is executed and its ResultSet is returned.

Specified by:
executeQuery in interface java.sql.PreparedStatement
Returns:
a ResultSet that contains the data produced by the * query - never null.
Throws:
java.sql.SQLException - if a database access error occurs

executeUpdate

public int executeUpdate()
                  throws java.sql.SQLException
Execute a SQL INSERT, UPDATE or DELETE statement. In addition, SQL statements that return nothing such as SQL DDL statements can be executed.

Specified by:
executeUpdate in interface java.sql.PreparedStatement
Returns:
either the row count for INSERT, UPDATE or DELETE; or 0 for SQL statements that return nothing.
Throws:
java.sql.SQLException - if a database access error occurs

compileQuery

protected java.lang.String compileQuery()
                                 throws java.sql.SQLException
Helper - this compiles the SQL query, inlining the parameters in the request String. This is identical to this.toString() except it throws an exception if a parameter was not set.

Returns:
the compiled query
Throws:
java.sql.SQLException - if an error occurs

doEscapeProcessing

protected java.lang.String doEscapeProcessing(java.lang.String x)
Escape the input string.
' is replaced by \'
\ is replaced by \\'
if connection.escapeProcessing is set to true, surround the new string with \'

Parameters:
x - the string to process
Returns:
escaped string

setNull

public void setNull(int parameterIndex,
                    int sqlType)
             throws java.sql.SQLException
Sets a parameter to SQL NULL.

Note: you must specify the parameters SQL type but we ignore it.

Specified by:
setNull in interface java.sql.PreparedStatement
Parameters:
parameterIndex - the first parameter is 1, etc...
sqlType - the SQL type code defined in java.sql.Types
Throws:
java.sql.SQLException - if a database access error occurs

setBoolean

public void setBoolean(int parameterIndex,
                       boolean x)
                throws java.sql.SQLException
Sets a parameter to a Java boolean value. The driver converts this to a SQL BIT value when it sends it to the database.

Specified by:
setBoolean in interface java.sql.PreparedStatement
Parameters:
parameterIndex - the first parameter is 1...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs

setByte

public void setByte(int parameterIndex,
                    byte x)
             throws java.sql.SQLException
Sets a parameter to a Java byte value.

Specified by:
setByte in interface java.sql.PreparedStatement
Parameters:
parameterIndex - the first parameter is 1...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs

setShort

public void setShort(int parameterIndex,
                     short x)
              throws java.sql.SQLException
Sets a parameter to a Java short value. The driver converts this to a SQL SMALLINT value when it sends it to the database.

Specified by:
setShort in interface java.sql.PreparedStatement
Parameters:
parameterIndex - the first parameter is 1...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs

setInt

public void setInt(int parameterIndex,
                   int x)
            throws java.sql.SQLException
Sets a parameter to a Java int value. The driver converts this to a SQL INTEGER value when it sends it to the database.

Specified by:
setInt in interface java.sql.PreparedStatement
Parameters:
parameterIndex - the first parameter is 1...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs

setLong

public void setLong(int parameterIndex,
                    long x)
             throws java.sql.SQLException
Sets a parameter to a Java long value. The driver converts this to a SQL BIGINT value when it sends it to the database.

Specified by:
setLong in interface java.sql.PreparedStatement
Parameters:
parameterIndex - the first parameter is 1...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs

setFloat

public void setFloat(int parameterIndex,
                     float x)
              throws java.sql.SQLException
Sets a parameter to a Java float value. The driver converts this to a SQL FLOAT value when it sends it to the database.

Specified by:
setFloat in interface java.sql.PreparedStatement
Parameters:
parameterIndex - the first parameter is 1...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs

setDouble

public void setDouble(int parameterIndex,
                      double x)
               throws java.sql.SQLException
Sets a parameter to a Java double value. The driver converts this to a SQL DOUBLE value when it sends it to the database.

Specified by:
setDouble in interface java.sql.PreparedStatement
Parameters:
parameterIndex - the first parameter is 1...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs

setBigDecimal

public void setBigDecimal(int parameterIndex,
                          java.math.BigDecimal x)
                   throws java.sql.SQLException
Sets a parameter to a java.lang.BigDecimal value. The driver converts this to a SQL NUMERIC value when it sends it to the database.

Specified by:
setBigDecimal in interface java.sql.PreparedStatement
Parameters:
parameterIndex - the first parameter is 1...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs

setString

public void setString(int parameterIndex,
                      java.lang.String x)
               throws java.sql.SQLException
Sets a parameter to a Java String value. The driver converts this to a SQL VARCHAR or LONGVARCHAR value (depending on the arguments size relative to the driver's limits on VARCHARs) when it sends it to the database.

Specified by:
setString in interface java.sql.PreparedStatement
Parameters:
parameterIndex - the first parameter is 1...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs

setBytes

public void setBytes(int parameterIndex,
                     byte[] x)
              throws java.sql.SQLException
Sets a parameter to a Java array of bytes.

Specified by:
setBytes in interface java.sql.PreparedStatement
Parameters:
parameterIndex - the first parameter is 1...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs

setDate

public void setDate(int parameterIndex,
                    java.sql.Date x)
             throws java.sql.SQLException
Sets a parameter to a java.sql.Date value. The driver converts this to a SQL DATE value when it sends it to the database.

Specified by:
setDate in interface java.sql.PreparedStatement
Parameters:
parameterIndex - the first parameter is 1...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs

setTime

public void setTime(int parameterIndex,
                    java.sql.Time x)
             throws java.sql.SQLException
Sets a parameter to a java.sql.Time value. The driver converts this to a SQL TIME value when it sends it to the database.

Specified by:
setTime in interface java.sql.PreparedStatement
Parameters:
parameterIndex - the first parameter is 1...));
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs

setTimestamp

public void setTimestamp(int parameterIndex,
                         java.sql.Timestamp x)
                  throws java.sql.SQLException
Sets a parameter to a java.sql.Timestamp value. The driver converts this to a SQL TIMESTAMP value when it sends it to the database.

Specified by:
setTimestamp in interface java.sql.PreparedStatement
Parameters:
parameterIndex - the first parameter is 1...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs

setAsciiStream

public void setAsciiStream(int parameterIndex,
                           java.io.InputStream x,
                           int length)
                    throws java.sql.SQLException
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. JDBC will read the data from the stream as needed, until it reaches end-of-file. 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:
setAsciiStream in interface java.sql.PreparedStatement
Parameters:
parameterIndex - the first parameter is 1...
x - the parameter value
length - the number of bytes in the stream
Throws:
java.sql.SQLException - if a database access error occurs

setUnicodeStream

public void setUnicodeStream(int parameterIndex,
                             java.io.InputStream x,
                             int length)
                      throws java.sql.SQLException
Deprecated.  

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. JDBC will read the data from the stream as needed, until it reaches end-of-file. The JDBC driver will do any necessary conversion from UNICODE to the database char format.

** DEPRECIATED IN JDBC 2 **

Note: this stream object can either be a standard Java stream object or your own subclass that implements the standard interface.

Specified by:
setUnicodeStream in interface java.sql.PreparedStatement
Parameters:
parameterIndex - the first parameter is 1...
x - the parameter value
length - the parameter length
Throws:
java.sql.SQLException - if a database access error occurs

setBinaryStream

public void setBinaryStream(int parameterIndex,
                            java.io.InputStream inStreamArg,
                            int length)
                     throws java.sql.SQLException
Stores a binary stream into parameters array, using an intermediate byte[]. 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. JDBC will read the data from the stream as needed, until it reaches end-of-file. This should be more or less equivalent to setBytes(blob.getBytes()).

Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.

Specified by:
setBinaryStream in interface java.sql.PreparedStatement
Parameters:
parameterIndex - the first parameter is 1...
inStreamArg - the parameter value
length - the parameter length
Throws:
java.sql.SQLException - if a database access error occurs
See Also:
PreparedStatement.setBinaryStream(int, java.io.InputStream, int)

clearParameters

public void clearParameters()
                     throws java.sql.SQLException
In general, parameter values remain in force for repeated used of a Statement. Setting a parameter value automatically clears its previous value. However, in coms cases, it is useful to immediately release the resources used by the current parameter values; this can be done by calling clearParameters().

Specified by:
clearParameters in interface java.sql.PreparedStatement
Throws:
java.sql.SQLException - if a database access error occurs

setObject

public void setObject(int parameterIndex,
                      java.lang.Object x,
                      int targetSqlType,
                      int scale)
               throws java.sql.SQLException
Sets the value of a parameter using an object; use the java.lang equivalent objects for integral values.

The given Java object will be converted to the targetSqlType before being sent to the database.

Note that this method may be used to pass database-specific abstract data types. This is done by using a Driver-specific Java type and using a targetSqlType of java.sql.Types.OTHER.

Specified by:
setObject in interface java.sql.PreparedStatement
Parameters:
parameterIndex - the first parameter is 1...
x - the object containing the input parameter value
targetSqlType - The SQL type to be send to the database
scale - for java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types this is the number of digits after the decimal. For all other types this value will be ignored.
Throws:
java.sql.SQLException - if a database access error or an incompatible type match occurs
See Also:
PreparedStatement.setObject(int, java.lang.Object, int, int)

setObject

public void setObject(int parameterIndex,
                      java.lang.Object x,
                      int targetSqlType)
               throws java.sql.SQLException
Specified by:
setObject in interface java.sql.PreparedStatement
Throws:
java.sql.SQLException
See Also:
PreparedStatement.setObject(int, java.lang.Object, int)

setObject

public void setObject(int parameterIndex,
                      java.lang.Object x)
               throws java.sql.SQLException
This stores an Object parameter into the parameters array.

Specified by:
setObject in interface java.sql.PreparedStatement
Parameters:
parameterIndex - the first parameter is 1...
x - the object to set
Throws:
java.sql.SQLException - if a database access error occurs

execute

public boolean execute()
                throws java.sql.SQLException
Some prepared statements return multiple results; the execute method handles these complex statements as well as the simpler form of statements handled by executeQuery() and executeUpdate().

Specified by:
execute in interface java.sql.PreparedStatement
Returns:
true if the next result is a ResultSet; false if it is an update count or there are no more results
Throws:
java.sql.SQLException - if a database access error occurs

toString

public java.lang.String toString()
Returns the SQL statement with the current template values substituted.

Note: : This is identical to compileQuery() except instead of throwing SQLException if a parameter is null, it places ? instead.

Returns:
the SQL statement

addBatch

public void addBatch()
              throws java.sql.SQLException
This parses the query and adds it to the current batch

Specified by:
addBatch in interface java.sql.PreparedStatement
Throws:
java.sql.SQLException - if an error occurs

executeBatch

public int[] executeBatch()
                   throws java.sql.BatchUpdateException
Execute a batch of commands

Specified by:
executeBatch in interface java.sql.Statement
Overrides:
executeBatch in class Statement
Returns:
an array containing update count that corresponding to the commands that executed successfully
Throws:
java.sql.BatchUpdateException - if an error occurs on one statement (the number of updated rows for the successfully executed statements can be found in BatchUpdateException.getUpdateCounts())

getMetaData

public java.sql.ResultSetMetaData getMetaData()
                                       throws java.sql.SQLException
Returns the MetaData for the last ResultSet returned.

Specified by:
getMetaData in interface java.sql.PreparedStatement
Returns:
The ResultSet Metadata
Throws:
java.sql.SQLException - if an error occurs

setArray

public void setArray(int i,
                     java.sql.Array x)
              throws java.sql.SQLException
Specified by:
setArray in interface java.sql.PreparedStatement
Throws:
java.sql.SQLException
See Also:
PreparedStatement.setArray(int, java.sql.Array)

setBlob

public void setBlob(int paramIndex,
                    java.sql.Blob sqlBlobParam)
             throws java.sql.SQLException
Specified by:
setBlob in interface java.sql.PreparedStatement
Throws:
java.sql.SQLException
See Also:
PreparedStatement.setBlob(int, java.sql.Blob)

setCharacterStream

public void setCharacterStream(int i,
                               java.io.Reader x,
                               int length)
                        throws java.sql.SQLException
Specified by:
setCharacterStream in interface java.sql.PreparedStatement
Throws:
java.sql.SQLException
See Also:
PreparedStatement.setCharacterStream(int, java.io.Reader, int)

setClob

public void setClob(int i,
                    java.sql.Clob clobArg)
             throws java.sql.SQLException
Specified by:
setClob in interface java.sql.PreparedStatement
Throws:
java.sql.SQLException
See Also:
PreparedStatement.setClob(int, java.sql.Clob)

setNull

public void setNull(int i,
                    int t,
                    java.lang.String s)
             throws java.sql.SQLException
Specified by:
setNull in interface java.sql.PreparedStatement
Throws:
java.sql.SQLException
See Also:
PreparedStatement.setNull(int, int, java.lang.String)

setRef

public void setRef(int i,
                   java.sql.Ref x)
            throws java.sql.SQLException
Specified by:
setRef in interface java.sql.PreparedStatement
Throws:
java.sql.SQLException
See Also:
PreparedStatement.setRef(int, java.sql.Ref)

setDate

public void setDate(int i,
                    java.sql.Date d,
                    java.util.Calendar cal)
             throws java.sql.SQLException
Specified by:
setDate in interface java.sql.PreparedStatement
Throws:
java.sql.SQLException
See Also:
PreparedStatement.setDate(int, java.sql.Date, java.util.Calendar)

setTime

public void setTime(int i,
                    java.sql.Time t,
                    java.util.Calendar cal)
             throws java.sql.SQLException
Specified by:
setTime in interface java.sql.PreparedStatement
Throws:
java.sql.SQLException
See Also:
PreparedStatement.setTime(int, java.sql.Time, java.util.Calendar)

setTimestamp

public void setTimestamp(int i,
                         java.sql.Timestamp t,
                         java.util.Calendar cal)
                  throws java.sql.SQLException
Specified by:
setTimestamp in interface java.sql.PreparedStatement
Throws:
java.sql.SQLException
See Also:
PreparedStatement.setTimestamp(int, java.sql.Timestamp, java.util.Calendar)

setURL

public void setURL(int parameterIndex,
                   java.net.URL x)
            throws java.sql.SQLException
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:
setURL in interface java.sql.PreparedStatement
Parameters:
parameterIndex - the first parameter is 1, the second is 2, ...
x - the java.net.URL object to be set
Throws:
java.sql.SQLException - if a database access error occurs
Since:
JDK 1.4

getParameterMetaData

public java.sql.ParameterMetaData getParameterMetaData()
                                                throws java.sql.SQLException
Retrieves the number, types and properties of this PreparedStatement object's parameters.

Specified by:
getParameterMetaData in interface java.sql.PreparedStatement
Returns:
a ParameterMetaData object that contains information about the number, types and properties of this PreparedStatement object's parameters
Throws:
java.sql.SQLException - if a database access error occurs
Since:
JDK 1.4
See Also:
ParameterMetaData

set

private void set(int paramIndex,
                 java.lang.String s)
          throws java.sql.SQLException
Actually stores the IN parameter into parameters String array. Called by most setXXX() methods.

Parameters:
paramIndex - the index into the inString
s - a string to be stored
Throws:
java.sql.SQLException - if something goes wrong

setWithTag

private void setWithTag(int paramIndex,
                        java.lang.String typeTag,
                        java.lang.String param)
                 throws java.sql.SQLException
Stores parameter and its type as a quoted String, so the controller can decode them back. Used when driverProcessed is false.

When isDriverProcessed() is false, we could avoid inlining the arguments and just tag them and send them apart as an object list. But this would imply a couple of changes elsewhere, among other: macro-handling, recoverylog,...

Parameters:
paramIndex - the index into the inString
typeTag - type of the parameter
param - the parameter string to be stored
Throws:
java.sql.SQLException - if something goes wrong
See Also:
setPreparedStatement(String, java.sql.PreparedStatement)

setGeneratedKeysFlag

protected void setGeneratedKeysFlag(int autoGeneratedKeys)
Set the auto generated key flag defined in Statement

Parameters:
autoGeneratedKeys - usually Statement.RETURN_GENERATED_KEYS
See Also:
Connection.prepareStatement(String, int)

setPreparedStatement

public static void setPreparedStatement(java.lang.String quotedRequest,
                                        java.sql.PreparedStatement backendPS)
                                 throws java.sql.SQLException
Static method to initialize a backend PreparedStatement by calling the appropriate setXXX methods on the request skeleton. Has to extract the tagged and inlined parameters from the sql String beforehand. Used by the controller, only when isDriverProcessed() is false.

Parameters:
quotedRequest - SQL statement with parameters to replace
backendPS - the preparedStatement to set
Throws:
java.sql.SQLException - if an error occurs
See Also:
setWithTag(int, String, String)


Copyright © 2002, 2005 - ObjectWeb Consortium - All Rights Reserved.