|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.objectweb.cjdbc.driver.Statement
org.objectweb.cjdbc.driver.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.
For instance, this is just a dirty copy/paste from the PostgreSQL driver ! Implementation has to be completly checked and revised.
DriverResultSet
,
PreparedStatement
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 |
FLOAT_TAG
Tag for a float parameter |
private java.lang.String[] |
inStrings
|
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_TAG
Tag for a setNull call |
static java.lang.String |
OBJECT_TAG
Tag for an object parameter |
private java.lang.StringBuffer |
sbuf
|
static java.lang.String |
SHORT_TAG
Tag for a short parameter |
protected java.lang.String |
sql
|
static java.lang.String |
STRING_TAG
Tag for a string parameter |
private java.lang.String[] |
templateStrings
|
static java.lang.String |
TIME_TAG
Tag for a time parameter |
static java.lang.String |
TIMESTAMP_TAG
Tag for a timestamp parameter |
Fields inherited from class org.objectweb.cjdbc.driver.Statement |
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 from the various parameters This is identical to toString() except it throws an exception if a parameter is unused. |
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() . |
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)
There are a lot of setXXX classes which all basically do the same thing. |
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 x,
int length)
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. |
void |
setBlob(int i,
java.sql.Blob x)
|
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 x)
|
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 into a parameter. |
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 sql,
java.sql.PreparedStatement ps)
Set a 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 tag,
java.lang.String s)
calls set with tags for driverProcessed=false |
java.lang.String |
toString()
Returns the SQL statement with the current template values substituted. |
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, executeBatch, 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 |
public static final java.lang.String BYTE_TAG
public static final java.lang.String BYTES_TAG
public static final java.lang.String BLOB_TAG
public static final java.lang.String CLOB_TAG
public static final java.lang.String BOOLEAN_TAG
public static final java.lang.String BIG_DECIMAL_TAG
public static final java.lang.String DATE_TAG
public static final java.lang.String DOUBLE_TAG
public static final java.lang.String FLOAT_TAG
public static final java.lang.String INTEGER_TAG
public static final java.lang.String LONG_TAG
public static final java.lang.String NULL_TAG
public static final java.lang.String OBJECT_TAG
public static final java.lang.String SHORT_TAG
public static final java.lang.String STRING_TAG
public static final java.lang.String TIME_TAG
public static final java.lang.String TIMESTAMP_TAG
protected java.lang.String sql
private java.lang.String[] templateStrings
private java.lang.String[] inStrings
private java.lang.StringBuffer sbuf
Constructor Detail |
public PreparedStatement(Connection connection, java.lang.String sqlStatement) throws java.sql.SQLException
connection
- the instanatiating connectionsqlStatement
- the SQL statement with ? for IN markers
java.sql.SQLException
- if something bad occursMethod Detail |
public void close() throws java.sql.SQLException
close
in interface java.sql.Statement
close
in class Statement
java.sql.SQLException
- if an error occurspublic java.sql.ResultSet executeQuery() throws java.sql.SQLException
ResultSet
is
returned.
executeQuery
in interface java.sql.PreparedStatement
ResultSet
that contains the data produced by the *
query - never null
.
java.sql.SQLException
- if a database access error occurspublic int executeUpdate() throws java.sql.SQLException
executeUpdate
in interface java.sql.PreparedStatement
INSERT
,
UPDATE
or DELETE
; or 0 for SQL
statements that return nothing.
java.sql.SQLException
- if a database access error occursprotected java.lang.String compileQuery() throws java.sql.SQLException
java.sql.SQLException
- if an error occursprotected java.lang.String doEscapeProcessing(java.lang.String x)
x
- the string to process
public void setNull(int parameterIndex, int sqlType) throws java.sql.SQLException
Note: you must specify the parameters SQL type but we ignore it.
setNull
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1, etc...sqlType
- the SQL type code defined in java.sql.Types
java.sql.SQLException
- if a database access error occurspublic void setBoolean(int parameterIndex, boolean x) throws java.sql.SQLException
setBoolean
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1...x
- the parameter value
java.sql.SQLException
- if a database access error occurspublic void setByte(int parameterIndex, byte x) throws java.sql.SQLException
setByte
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1...x
- the parameter value
java.sql.SQLException
- if a database access error occurspublic void setShort(int parameterIndex, short x) throws java.sql.SQLException
setShort
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1...x
- the parameter value
java.sql.SQLException
- if a database access error occurspublic void setInt(int parameterIndex, int x) throws java.sql.SQLException
setInt
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1...x
- the parameter value
java.sql.SQLException
- if a database access error occurspublic void setLong(int parameterIndex, long x) throws java.sql.SQLException
setLong
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1...x
- the parameter value
java.sql.SQLException
- if a database access error occurspublic void setFloat(int parameterIndex, float x) throws java.sql.SQLException
setFloat
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1...x
- the parameter value
java.sql.SQLException
- if a database access error occurspublic void setDouble(int parameterIndex, double x) throws java.sql.SQLException
setDouble
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1...x
- the parameter value
java.sql.SQLException
- if a database access error occurspublic void setBigDecimal(int parameterIndex, java.math.BigDecimal x) throws java.sql.SQLException
setBigDecimal
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1...x
- the parameter value
java.sql.SQLException
- if a database access error occurspublic void setString(int parameterIndex, java.lang.String x) throws java.sql.SQLException
setString
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1...x
- the parameter value
java.sql.SQLException
- if a database access error occurspublic void setBytes(int parameterIndex, byte[] x) throws java.sql.SQLException
Implementation note: with org.postgresql, this creates a large object, and stores the objects oid in this column.
setBytes
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1...x
- the parameter value
java.sql.SQLException
- if a database access error occurspublic void setDate(int parameterIndex, java.sql.Date x) throws java.sql.SQLException
setDate
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1...x
- the parameter value
java.sql.SQLException
- if a database access error occurspublic void setTime(int parameterIndex, java.sql.Time x) throws java.sql.SQLException
java.sql.Time
value. The driver
converts this to a SQL TIME value when it sends it to the database.
setTime
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1...));x
- the parameter value
java.sql.SQLException
- if a database access error occurspublic void setTimestamp(int parameterIndex, java.sql.Timestamp x) throws java.sql.SQLException
java.sql.Timestamp
value. The driver
converts this to a SQL TIMESTAMP value when it sends it to the database.
setTimestamp
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1...x
- the parameter value
java.sql.SQLException
- if a database access error occurspublic void setAsciiStream(int parameterIndex, java.io.InputStream x, int length) throws java.sql.SQLException
Note: this stream object can either be a standard Java stream object or your own subclass that implements the standard interface.
setAsciiStream
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1...x
- the parameter valuelength
- the number of bytes in the stream
java.sql.SQLException
- if a database access error occurspublic void setUnicodeStream(int parameterIndex, java.io.InputStream x, int length) throws java.sql.SQLException
** 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.
setUnicodeStream
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1...x
- the parameter valuelength
- the parameter length
java.sql.SQLException
- if a database access error occurspublic void setBinaryStream(int parameterIndex, java.io.InputStream x, int length) throws java.sql.SQLException
Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.
setBinaryStream
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1...x
- the parameter valuelength
- the parameter length
java.sql.SQLException
- if a database access error occurspublic void clearParameters() throws java.sql.SQLException
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()
.
clearParameters
in interface java.sql.PreparedStatement
java.sql.SQLException
- if a database access error occurspublic void setObject(int parameterIndex, java.lang.Object x, int targetSqlType, int scale) throws java.sql.SQLException
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
.
setObject
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1...x
- the object containing the input parameter valuetargetSqlType
- The SQL type to be send to the databasescale
- 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.
java.sql.SQLException
- if a database access error occurspublic void setObject(int parameterIndex, java.lang.Object x, int targetSqlType) throws java.sql.SQLException
setObject
in interface java.sql.PreparedStatement
java.sql.SQLException
PreparedStatement.setObject(int, java.lang.Object, int)
public void setObject(int parameterIndex, java.lang.Object x) throws java.sql.SQLException
setObject
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1...x
- the object to set
java.sql.SQLException
- if a database access error occurspublic boolean execute() throws java.sql.SQLException
executeQuery()
and executeUpdate()
.
execute
in interface java.sql.PreparedStatement
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
public java.lang.String toString()
Note: : This is identical to compileQuery()
except
instead of throwing SQLException if a parameter is null
, it
places ? instead.
public void addBatch() throws java.sql.SQLException
addBatch
in interface java.sql.PreparedStatement
java.sql.SQLException
- if an error occurspublic java.sql.ResultSetMetaData getMetaData() throws java.sql.SQLException
MetaData
for the last ResultSet
returned.
getMetaData
in interface java.sql.PreparedStatement
java.sql.SQLException
- if an error occurspublic void setArray(int i, java.sql.Array x) throws java.sql.SQLException
setArray
in interface java.sql.PreparedStatement
java.sql.SQLException
PreparedStatement.setArray(int, java.sql.Array)
public void setBlob(int i, java.sql.Blob x) throws java.sql.SQLException
setBlob
in interface java.sql.PreparedStatement
java.sql.SQLException
PreparedStatement.setBlob(int, java.sql.Blob)
public void setCharacterStream(int i, java.io.Reader x, int length) throws java.sql.SQLException
setCharacterStream
in interface java.sql.PreparedStatement
java.sql.SQLException
PreparedStatement.setCharacterStream(int, java.io.Reader,
int)
public void setClob(int i, java.sql.Clob x) throws java.sql.SQLException
setClob
in interface java.sql.PreparedStatement
java.sql.SQLException
PreparedStatement.setClob(int, java.sql.Clob)
public void setNull(int i, int t, java.lang.String s) throws java.sql.SQLException
setNull
in interface java.sql.PreparedStatement
java.sql.SQLException
PreparedStatement.setNull(int, int, java.lang.String)
public void setRef(int i, java.sql.Ref x) throws java.sql.SQLException
setRef
in interface java.sql.PreparedStatement
java.sql.SQLException
PreparedStatement.setRef(int, java.sql.Ref)
public void setDate(int i, java.sql.Date d, java.util.Calendar cal) throws java.sql.SQLException
setDate
in interface java.sql.PreparedStatement
java.sql.SQLException
PreparedStatement.setDate(int, java.sql.Date,
java.util.Calendar)
public void setTime(int i, java.sql.Time t, java.util.Calendar cal) throws java.sql.SQLException
setTime
in interface java.sql.PreparedStatement
java.sql.SQLException
PreparedStatement.setTime(int, java.sql.Time,
java.util.Calendar)
public void setTimestamp(int i, java.sql.Timestamp t, java.util.Calendar cal) throws java.sql.SQLException
setTimestamp
in interface java.sql.PreparedStatement
java.sql.SQLException
PreparedStatement.setTimestamp(int, java.sql.Timestamp,
java.util.Calendar)
public void setURL(int parameterIndex, java.net.URL x) throws java.sql.SQLException
java.net.URL
value. The driver converts this to an SQL DATALINK
value
when it sends it to the database.
setURL
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1, the second is 2, ...x
- the java.net.URL
object to be set
java.sql.SQLException
- if a database access error occurspublic java.sql.ParameterMetaData getParameterMetaData() throws java.sql.SQLException
PreparedStatement
object's parameters.
getParameterMetaData
in interface java.sql.PreparedStatement
ParameterMetaData
object that contains information
about the number, types and properties of this
PreparedStatement
object's parameters
java.sql.SQLException
- if a database access error occursParameterMetaData
private void set(int paramIndex, java.lang.String s) throws java.sql.SQLException
paramIndex
- the index into the inStrings
- a string to be stored
java.sql.SQLException
- if something goes wrongprivate void setWithTag(int paramIndex, java.lang.String tag, java.lang.String s) throws java.sql.SQLException
paramIndex
- the index into the inStringtag
- the tags
- a string to be stored
java.sql.SQLException
- if something goes wrongprotected void setGeneratedKeysFlag(int autoGeneratedKeys)
autoGeneratedKeys
- usually
Statement.RETURN_GENERATED_KEYS
Connection.prepareStatement(String, int)
public static void setPreparedStatement(java.lang.String sql, java.sql.PreparedStatement ps) throws java.sql.SQLException
sql
- sql statement with parameters to replaceps
- the preparedStatement to set
java.sql.SQLException
- if an error occurs
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |