Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.mysql.jdbc
Class Statement  view Statement download Statement.java

java.lang.Object
  extended bycom.mysql.jdbc.Statement
All Implemented Interfaces:
java.sql.Statement
Direct Known Subclasses:
PreparedStatement

public class Statement
extends java.lang.Object
implements java.sql.Statement

A Statement object is used for executing a static SQL statement and obtaining the results produced by it.

Only one ResultSet per Statement can be open at any point in time. Therefore, if the reading of one ResultSet is interleaved with the reading of another, each must have been generated by different Statements. All statement execute methods implicitly close a statement's current ResultSet if an open one exists.

Version:
$Id: Statement.java,v 1.20.2.26 2004/08/09 22:15:12 mmatthew Exp $

Field Summary
protected  java.util.List batchedArgs
          Holds batched commands
protected  SingleByteCharsetConverter charConverter
          The character converter to use (if available)
protected  java.lang.String charEncoding
          The character encoding to use (if available)
protected  Connection connection
          The connection that created us
protected  java.lang.String currentCatalog
          The catalog in use
protected  boolean doEscapeProcessing
          Should we process escape codes?
private  int fetchSize
          The number of rows to fetch at a time (currently ignored)
protected  boolean isClosed
          Has this statement been closed?
protected  long lastInsertId
          The auto_increment value for the last insert
protected  int maxFieldSize
          The max field size for this statement
protected  int maxRows
          The maximum number of rows to return for this statement (-1 means _all_ rows)
protected  boolean maxRowsChanged
          Has someone changed this for this statement?
protected  ResultSet nextResults
          The next result set
protected  java.util.List openResults
          List of currently-open ResultSets
protected  boolean pedantic
          Are we in pedantic mode?
protected  java.sql.SQLWarning pendingWarnings
          The pending warnings chain
protected  ResultSet results
          The current results
protected  int resultSetConcurrency
          The concurrency for this result set (updatable or not)
protected  int resultSetType
          The type of this result set (scroll sensitive or in-sensitive)
private  boolean serverSupportsConvertFn
          Does the server support CAST/CONVERT?
protected  int timeout
          The timeout for a query
protected  long updateCount
          The update count for this statement
protected  java.sql.SQLWarning warningChain
          The warnings chain.
 
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
Statement(Connection c, java.lang.String catalog)
          Constructor for a Statement.
 
Method Summary
 void addBatch(java.lang.String sql)
          DOCUMENT ME!
protected  void addWarning(java.sql.SQLWarning warning)
           
 void cancel()
          Cancel can be used by one thread to cancel a statement that is being executed by another thread.
protected  void checkClosed()
          Checks if closed() has been called, and throws an exception if so
 void clearBatch()
          JDBC 2.0 Make the set of commands in the current batch empty.
 void clearWarnings()
          After this call, getWarnings returns null until a new warning is reported for this Statement.
 void close()
          In many cases, it is desirable to immediately release a Statement's database and JDBC resources instead of waiting for this to happen when it is automatically closed.
protected  void closeAllOpenResults()
          Close any open result sets that have been 'held open'
protected  boolean createStreamingResultSet()
          We only stream result sets when they are forward-only, read-only, and the fetch size has been set to Integer.MIN_VALUE
 boolean execute(java.lang.String sql)
          Execute a SQL statement that may return multiple results.
 boolean execute(java.lang.String sql, int returnGeneratedKeys)
           
 boolean execute(java.lang.String sql, int[] generatedKeyIndices)
           
 boolean execute(java.lang.String sql, java.lang.String[] generatedKeyNames)
           
 int[] executeBatch()
          JDBC 2.0 Submit a batch of commands to the database for execution.
 java.sql.ResultSet executeQuery(java.lang.String sql)
          Execute a SQL statement that retruns a single ResultSet
 int executeUpdate(java.lang.String sql)
          Execute a SQL INSERT, UPDATE or DELETE statement.
private  int executeUpdate(java.lang.String sql, boolean clearWarnings)
           
 int executeUpdate(java.lang.String sql, int returnGeneratedKeys)
           
 int executeUpdate(java.lang.String sql, int[] generatedKeyIndices)
           
 int executeUpdate(java.lang.String sql, java.lang.String[] generatedKeyNames)
           
 java.sql.Connection getConnection()
          JDBC 2.0 Return the Connection that produced the Statement.
 int getFetchDirection()
          JDBC 2.0 Determine the fetch direction.
 int getFetchSize()
          JDBC 2.0 Determine the default fetch size.
 java.sql.ResultSet getGeneratedKeys()
          DOCUMENT ME!
 long getLastInsertID()
          getLastInsertID returns the value of the auto_incremented key after an executeQuery() or excute() call.
 long getLongUpdateCount()
          getLongUpdateCount returns the current result as an update count, if the result is a ResultSet or there are no more results, -1 is returned.
 int getMaxFieldSize()
          The maxFieldSize limit (in bytes) is the maximum amount of data returned for any column value; it only applies to BINARY, VARBINARY, LONGVARBINARY, CHAR, VARCHAR and LONGVARCHAR columns.
 int getMaxRows()
          The maxRows limit is set to limit the number of rows that any ResultSet can contain.
 boolean getMoreResults()
          getMoreResults moves to a Statement's next result.
 boolean getMoreResults(int current)
           
 int getQueryTimeout()
          The queryTimeout limit is the number of seconds the driver will wait for a Statement to execute.
private  int getRecordCountFromInfo(java.lang.String serverInfo)
          Parses actual record count from 'info' message
 java.sql.ResultSet getResultSet()
          getResultSet returns the current result as a ResultSet.
 int getResultSetConcurrency()
          JDBC 2.0 Determine the result set concurrency.
 int getResultSetHoldability()
           
 int getResultSetType()
          JDBC 2.0 Determine the result set type.
 int getUpdateCount()
          getUpdateCount returns the current result as an update count, if the result is a ResultSet or there are no more results, -1 is returned.
 java.sql.SQLWarning getWarnings()
          The first warning reported by calls on this Statement is returned.
 void setCursorName(java.lang.String name)
          setCursorName defines the SQL cursor name that will be used by subsequent execute methods.
 void setEscapeProcessing(boolean enable)
          If escape scanning is on (the default), the driver will do escape substitution before sending the SQL to the database.
 void setFetchDirection(int direction)
          JDBC 2.0 Give a hint as to the direction in which the rows in a result set will be processed.
 void setFetchSize(int rows)
          JDBC 2.0 Give the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed.
 void setMaxFieldSize(int max)
          Sets the maxFieldSize
 void setMaxRows(int max)
          Set the maximum number of rows
 void setQueryTimeout(int seconds)
          Sets the queryTimeout limit
(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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connection

protected Connection connection
The connection that created us


batchedArgs

protected java.util.List batchedArgs
Holds batched commands


openResults

protected java.util.List openResults
List of currently-open ResultSets


nextResults

protected ResultSet nextResults
The next result set


results

protected ResultSet results
The current results


warningChain

protected java.sql.SQLWarning warningChain
The warnings chain.


pendingWarnings

protected java.sql.SQLWarning pendingWarnings
The pending warnings chain


charConverter

protected SingleByteCharsetConverter charConverter
The character converter to use (if available)


charEncoding

protected java.lang.String charEncoding
The character encoding to use (if available)


currentCatalog

protected java.lang.String currentCatalog
The catalog in use


doEscapeProcessing

protected boolean doEscapeProcessing
Should we process escape codes?


isClosed

protected boolean isClosed
Has this statement been closed?


maxRowsChanged

protected boolean maxRowsChanged
Has someone changed this for this statement?


pedantic

protected boolean pedantic
Are we in pedantic mode?


maxFieldSize

protected int maxFieldSize
The max field size for this statement


maxRows

protected int maxRows
The maximum number of rows to return for this statement (-1 means _all_ rows)


resultSetConcurrency

protected int resultSetConcurrency
The concurrency for this result set (updatable or not)


resultSetType

protected int resultSetType
The type of this result set (scroll sensitive or in-sensitive)


timeout

protected int timeout
The timeout for a query


lastInsertId

protected long lastInsertId
The auto_increment value for the last insert


updateCount

protected long updateCount
The update count for this statement


fetchSize

private int fetchSize
The number of rows to fetch at a time (currently ignored)


serverSupportsConvertFn

private boolean serverSupportsConvertFn
Does the server support CAST/CONVERT?

Constructor Detail

Statement

public Statement(Connection c,
                 java.lang.String catalog)
          throws java.sql.SQLException
Constructor for a Statement.

Method Detail

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
JDBC 2.0 Return the Connection that produced the Statement.

Specified by:
getConnection in interface java.sql.Statement

setCursorName

public void setCursorName(java.lang.String name)
                   throws java.sql.SQLException
setCursorName defines the SQL cursor name that will be used by subsequent execute methods. This name can then be used in SQL positioned update/delete statements to identify the current row in the ResultSet generated by this statement. If a database doesn't support positioned update/delete, this method is a no-op.

Note: This MySQL driver does not support cursors.

Specified by:
setCursorName in interface java.sql.Statement

setEscapeProcessing

public void setEscapeProcessing(boolean enable)
                         throws java.sql.SQLException
If escape scanning is on (the default), the driver will do escape substitution before sending the SQL to the database.

Specified by:
setEscapeProcessing in interface java.sql.Statement

setFetchDirection

public void setFetchDirection(int direction)
                       throws java.sql.SQLException
JDBC 2.0 Give a hint as to the direction in which the rows in a result set will be processed. The hint applies only to result sets created using this Statement object. The default value is ResultSet.FETCH_FORWARD.

Specified by:
setFetchDirection in interface java.sql.Statement

getFetchDirection

public int getFetchDirection()
                      throws java.sql.SQLException
JDBC 2.0 Determine the fetch direction.

Specified by:
getFetchDirection in interface java.sql.Statement

setFetchSize

public void setFetchSize(int rows)
                  throws java.sql.SQLException
JDBC 2.0 Give the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed. The number of rows specified only affects result sets created using this statement. If the value specified is zero, then the hint is ignored. The default value is zero.

Specified by:
setFetchSize in interface java.sql.Statement

getFetchSize

public int getFetchSize()
                 throws java.sql.SQLException
JDBC 2.0 Determine the default fetch size.

Specified by:
getFetchSize in interface java.sql.Statement

getGeneratedKeys

public java.sql.ResultSet getGeneratedKeys()
                                    throws java.sql.SQLException
DOCUMENT ME!

Specified by:
getGeneratedKeys in interface java.sql.Statement

getLastInsertID

public long getLastInsertID()
getLastInsertID returns the value of the auto_incremented key after an executeQuery() or excute() call.

This gets around the un-threadsafe behavior of "select LAST_INSERT_ID()" which is tied to the Connection that created this Statement, and therefore could have had many INSERTS performed before one gets a chance to call "select LAST_INSERT_ID()".


getLongUpdateCount

public long getLongUpdateCount()
getLongUpdateCount returns the current result as an update count, if the result is a ResultSet or there are no more results, -1 is returned. It should only be called once per result.

This method returns longs as MySQL server versions newer than 3.22.4 return 64-bit values for update counts


setMaxFieldSize

public void setMaxFieldSize(int max)
                     throws java.sql.SQLException
Sets the maxFieldSize

Specified by:
setMaxFieldSize in interface java.sql.Statement

getMaxFieldSize

public int getMaxFieldSize()
                    throws java.sql.SQLException
The maxFieldSize limit (in bytes) is the maximum amount of data returned for any column value; it only applies to BINARY, VARBINARY, LONGVARBINARY, CHAR, VARCHAR and LONGVARCHAR columns. If the limit is exceeded, the excess data is silently discarded.

Specified by:
getMaxFieldSize in interface java.sql.Statement

setMaxRows

public void setMaxRows(int max)
                throws java.sql.SQLException
Set the maximum number of rows

Specified by:
setMaxRows in interface java.sql.Statement

getMaxRows

public int getMaxRows()
               throws java.sql.SQLException
The maxRows limit is set to limit the number of rows that any ResultSet can contain. If the limit is exceeded, the excess rows are silently dropped.

Specified by:
getMaxRows in interface java.sql.Statement

getMoreResults

public boolean getMoreResults()
                       throws java.sql.SQLException
getMoreResults moves to a Statement's next result. If it returns true, this result is a ResulSet.

Specified by:
getMoreResults in interface java.sql.Statement

getMoreResults

public boolean getMoreResults(int current)
                       throws java.sql.SQLException
Specified by:
getMoreResults in interface java.sql.Statement

setQueryTimeout

public void setQueryTimeout(int seconds)
                     throws java.sql.SQLException
Sets the queryTimeout limit

Specified by:
setQueryTimeout in interface java.sql.Statement

getQueryTimeout

public int getQueryTimeout()
                    throws java.sql.SQLException
The queryTimeout limit is the number of seconds the driver will wait for a Statement to execute. If the limit is exceeded, a java.sql.SQLException is thrown.

Specified by:
getQueryTimeout in interface java.sql.Statement

getResultSet

public java.sql.ResultSet getResultSet()
                                throws java.sql.SQLException
getResultSet returns the current result as a ResultSet. It should only be called once per result.

Specified by:
getResultSet in interface java.sql.Statement

getResultSetConcurrency

public int getResultSetConcurrency()
                            throws java.sql.SQLException
JDBC 2.0 Determine the result set concurrency.

Specified by:
getResultSetConcurrency in interface java.sql.Statement

getResultSetHoldability

public int getResultSetHoldability()
                            throws java.sql.SQLException
Specified by:
getResultSetHoldability in interface java.sql.Statement

getResultSetType

public int getResultSetType()
                     throws java.sql.SQLException
JDBC 2.0 Determine the result set type.

Specified by:
getResultSetType in interface java.sql.Statement

getUpdateCount

public int getUpdateCount()
                   throws java.sql.SQLException
getUpdateCount returns the current result as an update count, if the result is a ResultSet or there are no more results, -1 is returned. It should only be called once per result.

Specified by:
getUpdateCount in interface java.sql.Statement

getWarnings

public java.sql.SQLWarning getWarnings()
                                throws java.sql.SQLException
The first warning reported by calls on this Statement is returned. A Statement's execute methods clear its java.sql.SQLWarning chain. Subsequent Statement warnings will be chained to this java.sql.SQLWarning.

The Warning chain is automatically cleared each time a statement is (re)executed.

Note: If you are processing a ResultSet then any warnings associated with ResultSet reads will be chained on the ResultSet object.

Specified by:
getWarnings in interface java.sql.Statement

addBatch

public void addBatch(java.lang.String sql)
              throws java.sql.SQLException
DOCUMENT ME!

Specified by:
addBatch in interface java.sql.Statement

cancel

public void cancel()
            throws java.sql.SQLException
Cancel can be used by one thread to cancel a statement that is being executed by another thread. However this driver is synchronous, so this really has no meaning - we define it as a no-op (i.e. you can't cancel, but there is no error if you try.)

Specified by:
cancel in interface java.sql.Statement

clearBatch

public void clearBatch()
                throws java.sql.SQLException
JDBC 2.0 Make the set of commands in the current batch empty. This method is optional.

Specified by:
clearBatch in interface java.sql.Statement

clearWarnings

public void clearWarnings()
                   throws java.sql.SQLException
After this call, getWarnings returns null until a new warning is reported for this Statement.

Specified by:
clearWarnings in interface java.sql.Statement

close

public void close()
           throws java.sql.SQLException
In many cases, it is desirable to immediately release a Statement's database and JDBC resources instead of waiting for this to happen when it is automatically closed. The close method provides this immediate release.

Note: A Statement is automatically closed when it is garbage collected. When a Statement is closed, its current ResultSet, if one exists, is also closed.

Specified by:
close in interface java.sql.Statement

execute

public boolean execute(java.lang.String sql)
                throws java.sql.SQLException
Execute a SQL statement that may return multiple results. We don't have to worry about this since we do not support multiple ResultSets. You can use getResultSet or getUpdateCount to retrieve the result.

Specified by:
execute in interface java.sql.Statement

execute

public boolean execute(java.lang.String sql,
                       int returnGeneratedKeys)
                throws java.sql.SQLException
Specified by:
execute in interface java.sql.Statement

execute

public boolean execute(java.lang.String sql,
                       int[] generatedKeyIndices)
                throws java.sql.SQLException
Specified by:
execute in interface java.sql.Statement

execute

public boolean execute(java.lang.String sql,
                       java.lang.String[] generatedKeyNames)
                throws java.sql.SQLException
Specified by:
execute in interface java.sql.Statement

executeBatch

public int[] executeBatch()
                   throws java.sql.SQLException
JDBC 2.0 Submit a batch of commands to the database for execution. This method is optional.

Specified by:
executeBatch in interface java.sql.Statement

executeQuery

public java.sql.ResultSet executeQuery(java.lang.String sql)
                                throws java.sql.SQLException
Execute a SQL statement that retruns a single ResultSet

Specified by:
executeQuery in interface java.sql.Statement

executeUpdate

public int executeUpdate(java.lang.String sql)
                  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 Any IDs generated for AUTO_INCREMENT fields can be retrieved by casting this Statement to org.gjt.mm.mysql.Statement and calling the getLastInsertID() method.

Specified by:
executeUpdate in interface java.sql.Statement

executeUpdate

private int executeUpdate(java.lang.String sql,
                          boolean clearWarnings)
                   throws java.sql.SQLException

executeUpdate

public int executeUpdate(java.lang.String sql,
                         int returnGeneratedKeys)
                  throws java.sql.SQLException
Specified by:
executeUpdate in interface java.sql.Statement

executeUpdate

public int executeUpdate(java.lang.String sql,
                         int[] generatedKeyIndices)
                  throws java.sql.SQLException
Specified by:
executeUpdate in interface java.sql.Statement

executeUpdate

public int executeUpdate(java.lang.String sql,
                         java.lang.String[] generatedKeyNames)
                  throws java.sql.SQLException
Specified by:
executeUpdate in interface java.sql.Statement

checkClosed

protected void checkClosed()
                    throws java.sql.SQLException
Checks if closed() has been called, and throws an exception if so


closeAllOpenResults

protected void closeAllOpenResults()
Close any open result sets that have been 'held open'


createStreamingResultSet

protected boolean createStreamingResultSet()
We only stream result sets when they are forward-only, read-only, and the fetch size has been set to Integer.MIN_VALUE


setResultSetConcurrency

void setResultSetConcurrency(int concurrencyFlag)
Sets the concurrency for result sets generated by this statement


setResultSetType

void setResultSetType(int typeFlag)
Sets the result set type for result sets generated by this statement


addWarning

protected void addWarning(java.sql.SQLWarning warning)

getRecordCountFromInfo

private int getRecordCountFromInfo(java.lang.String serverInfo)
Parses actual record count from 'info' message