|
|||||||||||
| 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.
ResultSet,
PreparedStatement| Field Summary | |
private java.lang.String[] |
inStrings
|
private java.lang.StringBuffer |
sbuf
|
protected java.lang.String |
sql
|
private java.lang.String[] |
templateStrings
|
| Fields inherited from class org.objectweb.cjdbc.driver.Statement |
connection, escapeProcessing, generatedKeys, generatedKeysFlag |
| 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. |
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 parameterIndex,
java.sql.Blob x)
Sets a parameter to a java.sql.Blob value. |
void |
setBlob(int i,
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.
|
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. |
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 |
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 occurs| Method Detail |
public void close()
throws java.sql.SQLException
close in interface java.sql.Statementclose in class Statementjava.sql.SQLException - if an error occurs
public java.sql.ResultSet executeQuery()
throws java.sql.SQLException
ResultSet
is returned.
executeQuery in interface java.sql.PreparedStatementResultSet that contains the data produced
by the * query - never null.
java.sql.SQLException - if a database access error occurs
public int executeUpdate()
throws java.sql.SQLException
executeUpdate in interface java.sql.PreparedStatementINSERT, UPDATE
or DELETE; or 0
for SQL statements that return nothing.
java.sql.SQLException - if a database access error occurs
protected java.lang.String compileQuery()
throws java.sql.SQLException
java.sql.SQLException - if an error occurs
public void setNull(int parameterIndex,
int sqlType)
throws java.sql.SQLException
Note: you must specify the parameters SQL type (although PostgreSQL ignores it)
setNull in interface java.sql.PreparedStatementparameterIndex - the first parameter is 1, etc...sqlType - the SQL type code defined in java.sql.Types
java.sql.SQLException - if a database access error occurs
public void setBoolean(int parameterIndex,
boolean x)
throws java.sql.SQLException
setBoolean in interface java.sql.PreparedStatementparameterIndex - the first parameter is 1...x - the parameter value
java.sql.SQLException - if a database access error occurs
public void setByte(int parameterIndex,
byte x)
throws java.sql.SQLException
setByte in interface java.sql.PreparedStatementparameterIndex - the first parameter is 1...x - the parameter value
java.sql.SQLException - if a database access error occurs
public void setShort(int parameterIndex,
short x)
throws java.sql.SQLException
setShort in interface java.sql.PreparedStatementparameterIndex - the first parameter is 1...x - the parameter value
java.sql.SQLException - if a database access error occurs
public void setInt(int parameterIndex,
int x)
throws java.sql.SQLException
setInt in interface java.sql.PreparedStatementparameterIndex - the first parameter is 1...x - the parameter value
java.sql.SQLException - if a database access error occurs
public void setLong(int parameterIndex,
long x)
throws java.sql.SQLException
setLong in interface java.sql.PreparedStatementparameterIndex - the first parameter is 1...x - the parameter value
java.sql.SQLException - if a database access error occurs
public void setFloat(int parameterIndex,
float x)
throws java.sql.SQLException
setFloat in interface java.sql.PreparedStatementparameterIndex - the first parameter is 1...x - the parameter value
java.sql.SQLException - if a database access error occurs
public void setDouble(int parameterIndex,
double x)
throws java.sql.SQLException
setDouble in interface java.sql.PreparedStatementparameterIndex - the first parameter is 1...x - the parameter value
java.sql.SQLException - if a database access error occurs
public void setBigDecimal(int parameterIndex,
java.math.BigDecimal x)
throws java.sql.SQLException
setBigDecimal in interface java.sql.PreparedStatementparameterIndex - the first parameter is 1...x - the parameter value
java.sql.SQLException - if a database access error occurs
public void setBlob(int parameterIndex,
java.sql.Blob x)
throws java.sql.SQLException
java.sql.Blob value.
setBlob in interface java.sql.PreparedStatementparameterIndex - the first parameter is 1...x - the parameter value
java.sql.SQLException - if a database access error occurs
public void setString(int parameterIndex,
java.lang.String x)
throws java.sql.SQLException
setString in interface java.sql.PreparedStatementparameterIndex - the first parameter is 1...x - the parameter value
java.sql.SQLException - if a database access error occurs
public 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.PreparedStatementparameterIndex - the first parameter is 1...x - the parameter value
java.sql.SQLException - if a database access error occurs
public void setDate(int parameterIndex,
java.sql.Date x)
throws java.sql.SQLException
setDate in interface java.sql.PreparedStatementparameterIndex - the first parameter is 1...x - the parameter value
java.sql.SQLException - if a database access error occurs
public 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.PreparedStatementparameterIndex - the first parameter is 1...));x - the parameter value
java.sql.SQLException - if a database access error occurs
public 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.PreparedStatementparameterIndex - the first parameter is 1...x - the parameter value
java.sql.SQLException - if a database access error occurs
public 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.PreparedStatementparameterIndex - the first parameter is 1...x - the parameter valuelength - the number of bytes in the stream
java.sql.SQLException - if a database access error occurs
public 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.PreparedStatementparameterIndex - the first parameter is 1...x - the parameter valuelength - the parameter length
java.sql.SQLException - if a database access error occurs
public 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.PreparedStatementparameterIndex - the first parameter is 1...x - the parameter valuelength - the parameter length
java.sql.SQLException - if a database access error occurs
public 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.PreparedStatementjava.sql.SQLException - if a database access error occurs
public 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.PreparedStatementparameterIndex - 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 occurs
public void setObject(int parameterIndex,
java.lang.Object x,
int targetSqlType)
throws java.sql.SQLException
setObject in interface java.sql.PreparedStatementjava.sql.SQLExceptionPreparedStatement.setObject(int, java.lang.Object, int)
public void setObject(int parameterIndex,
java.lang.Object x)
throws java.sql.SQLException
setObject in interface java.sql.PreparedStatementparameterIndex - the first parameter is 1...x - the object to set
java.sql.SQLException - if a database access error occurs
public boolean execute()
throws java.sql.SQLException
executeQuery() and
executeUpdate().
execute in interface java.sql.PreparedStatementtrue 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 occurspublic 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.PreparedStatementjava.sql.SQLException - if an error occurs
public java.sql.ResultSetMetaData getMetaData()
throws java.sql.SQLException
MetaData for the last ResultSet
returned.
getMetaData in interface java.sql.PreparedStatementjava.sql.SQLException - if an error occurs
public void setArray(int i,
java.sql.Array x)
throws java.sql.SQLException
setArray in interface java.sql.PreparedStatementjava.sql.SQLExceptionPreparedStatement.setArray(int, java.sql.Array)
public void setBlob(int i,
Blob x)
throws java.sql.SQLException
java.sql.SQLExceptionPreparedStatement.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.PreparedStatementjava.sql.SQLExceptionPreparedStatement.setCharacterStream(int, java.io.Reader, int)
public void setClob(int i,
java.sql.Clob x)
throws java.sql.SQLException
setClob in interface java.sql.PreparedStatementjava.sql.SQLExceptionPreparedStatement.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.PreparedStatementjava.sql.SQLExceptionPreparedStatement.setNull(int, int, java.lang.String)
public void setRef(int i,
java.sql.Ref x)
throws java.sql.SQLException
setRef in interface java.sql.PreparedStatementjava.sql.SQLExceptionPreparedStatement.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.PreparedStatementjava.sql.SQLExceptionPreparedStatement.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.PreparedStatementjava.sql.SQLExceptionPreparedStatement.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.PreparedStatementjava.sql.SQLExceptionPreparedStatement.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.PreparedStatementparameterIndex - 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 occurs
public java.sql.ParameterMetaData getParameterMetaData()
throws java.sql.SQLException
PreparedStatement object's parameters.
getParameterMetaData in interface java.sql.PreparedStatementParameterMetaData 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 wrongprotected void setGeneratedKeysFlag(int autoGeneratedKeys)
autoGeneratedKeys - usually Statement.RETURN_GENERATED_KEYSConnection.prepareStatement(String, int)
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||