|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.mysql.jdbc.Statement
com.mysql.jdbc.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.
ResultSet
,
PreparedStatement
Nested Class Summary | |
(package private) class |
PreparedStatement.BatchParams
|
(package private) class |
PreparedStatement.ParseInfo
|
Field Summary |
Fields inherited from class com.mysql.jdbc.Statement |
batchedArgs, charConverter, charEncoding, connection, currentCatalog, doEscapeProcessing, isClosed, lastInsertId, maxFieldSize, maxRows, maxRowsChanged, nextResults, openResults, pedantic, pendingWarnings, results, resultSetConcurrency, resultSetType, timeout, updateCount, warningChain |
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 conn,
java.lang.String sql,
java.lang.String catalog)
Constructor for the PreparedStatement class. |
|
PreparedStatement(Connection conn,
java.lang.String sql,
java.lang.String catalog,
PreparedStatement.ParseInfo cachedParseInfo)
Creates a new PreparedStatement object. |
Method Summary | |
void |
addBatch()
JDBC 2.0 Add a set of parameters to the batch. |
void |
clearParameters()
In general, parameter values remain in force for repeated used of a Statement. |
void |
close()
Closes this prepared statement and releases all resources. |
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()
JDBC 2.0 Submit a batch of commands to the database for execution. |
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. |
protected int |
executeUpdate(byte[][] batchedParameterStrings,
java.io.InputStream[] batchedParameterStreams,
boolean[] batchedIsStream,
int[] batchedStreamLengths,
boolean[] batchedIsNull)
Added to allow batch-updates |
(package private) byte[] |
getBytes(int parameterIndex)
|
java.sql.ResultSet |
getGeneratedKeys()
DOCUMENT ME! |
java.sql.ResultSetMetaData |
getMetaData()
The number, types and properties of a ResultSet's columns are provided by the getMetaData method. |
java.sql.ParameterMetaData |
getParameterMetaData()
|
(package private) PreparedStatement.ParseInfo |
getParseInfo()
|
(package private) boolean |
isNull(int paramIndex)
|
void |
setArray(int i,
java.sql.Array x)
JDBC 2.0 Set an Array parameter. |
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)
Set a parameter to a java.math.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)
JDBC 2.0 Set a BLOB parameter. |
void |
setBoolean(int parameterIndex,
boolean x)
Set a parameter to a Java boolean value. |
void |
setByte(int parameterIndex,
byte x)
Set a parameter to a Java byte value. |
void |
setBytes(int parameterIndex,
byte[] x)
Set a parameter to a Java array of bytes. |
protected void |
setBytes(int parameterIndex,
byte[] x,
boolean checkForIntroducer)
|
protected void |
setBytesNoEscape(int parameterIndex,
byte[] parameterAsBytes)
Used by updatable result sets for refreshRow() because the parameter has already been escaped for updater or inserter prepared statements. |
void |
setCharacterStream(int parameterIndex,
java.io.Reader reader,
int length)
JDBC 2.0 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. |
void |
setClob(int i,
java.sql.Clob x)
JDBC 2.0 Set a CLOB parameter. |
void |
setDate(int parameterIndex,
java.sql.Date x)
Set a parameter to a java.sql.Date value. |
void |
setDate(int parameterIndex,
java.sql.Date x,
java.util.Calendar cal)
Set a parameter to a java.sql.Date value. |
void |
setDouble(int parameterIndex,
double x)
Set a parameter to a Java double value. |
void |
setFloat(int parameterIndex,
float x)
Set a parameter to a Java float value. |
void |
setInt(int parameterIndex,
int x)
Set a parameter to a Java int value. |
void |
setLong(int parameterIndex,
long x)
Set a parameter to a Java long value. |
void |
setNull(int parameterIndex,
int sqlType)
Set a parameter to SQL NULL |
void |
setNull(int parameterIndex,
int sqlType,
java.lang.String arg)
Set a parameter to SQL NULL. |
void |
setObject(int parameterIndex,
java.lang.Object parameterObj)
Sets the given parameter to the given object. |
void |
setObject(int parameterIndex,
java.lang.Object parameterObj,
int targetSqlType)
Set the value of a parameter using an object; use the java.lang equivalent objects for integral values. |
void |
setObject(int parameterIndex,
java.lang.Object parameterObj,
int targetSqlType,
int scale)
Set 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)
JDBC 2.0 Set a REF(<structured-type>) parameter. |
(package private) void |
setResultSetConcurrency(int concurrencyFlag)
Sets the concurrency for result sets generated by this statement |
(package private) void |
setResultSetType(int typeFlag)
Sets the result set type for result sets generated by this statement |
protected void |
setRetrieveGeneratedKeys(boolean retrieveGeneratedKeys)
Sets wheather or not this statement should retreive generated keys. |
void |
setShort(int parameterIndex,
short x)
Set a parameter to a Java short value. |
void |
setString(int parameterIndex,
java.lang.String x)
Set a parameter to a Java String value. |
void |
setTime(int parameterIndex,
java.sql.Time x)
Set a parameter to a java.sql.Time value. |
void |
setTime(int parameterIndex,
java.sql.Time x,
java.util.Calendar cal)
Set a parameter to a java.sql.Time value. |
void |
setTimestamp(int parameterIndex,
java.sql.Timestamp x)
Set a parameter to a java.sql.Timestamp value. |
void |
setTimestamp(int parameterIndex,
java.sql.Timestamp x,
java.util.Calendar cal)
Set a parameter to a java.sql.Timestamp value. |
void |
setUnicodeStream(int parameterIndex,
java.io.InputStream x,
int length)
Deprecated. |
void |
setURL(int parameterIndex,
java.net.URL arg)
|
java.lang.String |
toString()
Returns this PreparedStatement represented as a string. |
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, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getUpdateCount, getWarnings, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setMaxFieldSize, setMaxRows, setQueryTimeout |
Constructor Detail |
public PreparedStatement(Connection conn, java.lang.String sql, java.lang.String catalog) throws java.sql.SQLException
conn
- the connection creating this statementsql
- the SQL for this statementcatalog
- the catalog/database this statement should be issued
against
java.sql.SQLException
- if a database error occurs.public PreparedStatement(Connection conn, java.lang.String sql, java.lang.String catalog, PreparedStatement.ParseInfo cachedParseInfo) throws java.sql.SQLException
conn
- the connection creating this statementsql
- the SQL for this statementcatalog
- the catalog/database this statement should be issued
againstcachedParseInfo
- already created parseInfo.
java.sql.SQLException
- DOCUMENT ME!Method Detail |
public void setArray(int i, java.sql.Array x) throws java.sql.SQLException
setArray
in interface java.sql.PreparedStatement
i
- the first parameter is 1, the second is 2, ...x
- an object representing an SQL array
java.sql.SQLException
- because this method is not implemented.
NotImplemented
- DOCUMENT ME!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.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 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 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 number of bytes to read from the stream (ignored)
java.sql.SQLException
- if a database access error occurs
java.sql.SQLException
- DOCUMENT ME!public void setBlob(int i, java.sql.Blob x) throws java.sql.SQLException
setBlob
in interface java.sql.PreparedStatement
i
- the first parameter is 1, the second is 2, ...x
- an object representing a BLOB
java.sql.SQLException
- if a database 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 setBytes(int parameterIndex, byte[] x) throws java.sql.SQLException
setBytes
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1...x
- the parameter value
java.sql.SQLException
- if a database access error occursprotected void setBytes(int parameterIndex, byte[] x, boolean checkForIntroducer) throws java.sql.SQLException
java.sql.SQLException
public void setCharacterStream(int parameterIndex, java.io.Reader reader, 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.
setCharacterStream
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1, the second is 2, ...reader
- the java reader which contains the UNICODE datalength
- the number of characters in the stream
java.sql.SQLException
- if a database-access error occurs.public void setClob(int i, java.sql.Clob x) throws java.sql.SQLException
setClob
in interface java.sql.PreparedStatement
i
- the first parameter is 1, the second is 2, ...x
- an object representing a CLOB
java.sql.SQLException
- if a database 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 setDate(int parameterIndex, java.sql.Date x, java.util.Calendar cal) throws java.sql.SQLException
setDate
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1, the second is 2, ...x
- the parameter valuecal
- the calendar to interpret the date with
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.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 java.sql.ResultSet getGeneratedKeys() throws java.sql.SQLException
Statement
getGeneratedKeys
in interface java.sql.Statement
getGeneratedKeys
in class Statement
java.sql.SQLException
- DOCUMENT ME!public 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 java.sql.ResultSetMetaData getMetaData() throws java.sql.SQLException
getMetaData
in interface java.sql.PreparedStatement
java.sql.SQLException
- if a database-access error occurs.public void setNull(int parameterIndex, int sqlType) throws java.sql.SQLException
Note: You must specify the parameters SQL type (although MySQL ignores 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 setNull(int parameterIndex, int sqlType, java.lang.String arg) throws java.sql.SQLException
Note: You must specify the parameter's SQL type.
setNull
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1, the second is 2, ...sqlType
- SQL type code defined by java.sql.Typesarg
- argument parameters for null
java.sql.SQLException
- if a database-access error occurs.public void setObject(int parameterIndex, java.lang.Object parameterObj, int targetSqlType, int scale) throws java.sql.SQLException
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...parameterObj
- 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
java.sql.SQLException
- DOCUMENT ME!public void setObject(int parameterIndex, java.lang.Object parameterObj, int targetSqlType) throws java.sql.SQLException
setObject
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1...parameterObj
- the object containing the input parameter valuetargetSqlType
- The SQL type to be send to the database
java.sql.SQLException
- if an error occurspublic void setObject(int parameterIndex, java.lang.Object parameterObj) throws java.sql.SQLException
setObject
in interface java.sql.PreparedStatement
parameterIndex
- the parameter to set.parameterObj
- the object to use as a value for the parameter.
java.sql.SQLException
- if an error occurs.public java.sql.ParameterMetaData getParameterMetaData() throws java.sql.SQLException
getParameterMetaData
in interface java.sql.PreparedStatement
java.sql.SQLException
getParameterMetaData()
public void setRef(int i, java.sql.Ref x) throws java.sql.SQLException
setRef
in interface java.sql.PreparedStatement
i
- the first parameter is 1, the second is 2, ...x
- an object representing data of an SQL REF Type
java.sql.SQLException
- if a database error occurs
NotImplemented
- DOCUMENT ME!public 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 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 error occurs.public void setTime(int parameterIndex, java.sql.Time x) throws java.sql.SQLException
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 setTime(int parameterIndex, java.sql.Time x, java.util.Calendar cal) throws java.sql.SQLException
setTime
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1, the second is 2, ...x
- the parameter valuecal
- the cal specifying the timezone
java.sql.SQLException
- if a database-access error occurs.public void setTimestamp(int parameterIndex, java.sql.Timestamp x) throws java.sql.SQLException
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 setTimestamp(int parameterIndex, java.sql.Timestamp x, java.util.Calendar cal) throws java.sql.SQLException
setTimestamp
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1, the second is 2, ...x
- the parameter valuecal
- the calendar specifying the timezone to use
java.sql.SQLException
- if a database-access error occurs.public void setURL(int parameterIndex, java.net.URL arg) throws java.sql.SQLException
setURL
in interface java.sql.PreparedStatement
java.sql.SQLException
setURL(int, URL)
public void setUnicodeStream(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.
setUnicodeStream
in interface java.sql.PreparedStatement
parameterIndex
- the first parameter is 1...x
- the parameter valuelength
- the number of bytes to read from the stream
java.sql.SQLException
- if a database access error occurspublic void addBatch() throws java.sql.SQLException
addBatch
in interface java.sql.PreparedStatement
java.sql.SQLException
- if a database-access error occurs.Statement.addBatch(java.lang.String)
public void clearParameters() throws java.sql.SQLException
clearParameters
in interface java.sql.PreparedStatement
java.sql.SQLException
- if a database access error occurspublic void close() throws java.sql.SQLException
close
in interface java.sql.Statement
close
in class Statement
java.sql.SQLException
- if database error occurs.public boolean execute() throws java.sql.SQLException
execute
in interface java.sql.PreparedStatement
java.sql.SQLException
- if a database error occurs.public int[] executeBatch() throws java.sql.SQLException
executeBatch
in interface java.sql.Statement
executeBatch
in class Statement
java.sql.SQLException
- if a database-access error occurs, or the driver
does not support batch statements
java.sql.BatchUpdateException
- DOCUMENT ME!public java.sql.ResultSet executeQuery() throws java.sql.SQLException
executeQuery
in interface java.sql.PreparedStatement
java.sql.SQLException
- if a database error occurs.public int executeUpdate() throws java.sql.SQLException
executeUpdate
in interface java.sql.PreparedStatement
java.sql.SQLException
- if a database access error occurspublic java.lang.String toString()
java.lang.RuntimeException
- if an error occursprotected void setBytesNoEscape(int parameterIndex, byte[] parameterAsBytes) throws java.sql.SQLException
parameterIndex
- the parameter to set.parameterAsBytes
- the parameter as a string.
java.sql.SQLException
- if an error occursprotected void setRetrieveGeneratedKeys(boolean retrieveGeneratedKeys)
retrieveGeneratedKeys
- protected int executeUpdate(byte[][] batchedParameterStrings, java.io.InputStream[] batchedParameterStreams, boolean[] batchedIsStream, int[] batchedStreamLengths, boolean[] batchedIsNull) throws java.sql.SQLException
batchedParameterStrings
- string values used in single statementbatchedParameterStreams
- stream values used in single statementbatchedIsStream
- flags for streams used in single statementbatchedStreamLengths
- lengths of streams to be read.batchedIsNull
- flags for parameters that are null
java.sql.SQLException
- if a database error occurs
java.sql.SQLException
- DOCUMENT ME!byte[] getBytes(int parameterIndex) throws java.sql.SQLException
java.sql.SQLException
boolean isNull(int paramIndex)
PreparedStatement.ParseInfo getParseInfo()
void setResultSetConcurrency(int concurrencyFlag)
setResultSetConcurrency
in class Statement
concurrencyFlag
- the result set concurrency flag from the
ResultSet interface.void setResultSetType(int typeFlag)
setResultSetType
in class Statement
typeFlag
- the result set type from the ResultSet interface
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |