org.h2.jdbc
Class JdbcStatement

java.lang.Object
  extended by org.h2.message.TraceObject
      extended by org.h2.jdbc.JdbcStatement
All Implemented Interfaces:
java.sql.Statement
Direct Known Subclasses:
JdbcPreparedStatement

public class JdbcStatement
extends TraceObject
implements java.sql.Statement

Represents a statement.


Field Summary
protected  boolean closedByResultSet
           
protected  JdbcConnection conn
           
protected  int fetchSize
           
protected  int maxRows
           
protected  JdbcResultSet resultSet
           
protected  int resultSetConcurrency
           
protected  int resultSetType
           
protected  SessionInterface session
           
protected  int updateCount
           
 
Fields inherited from class org.h2.message.TraceObject
ARRAY, BLOB, CALLABLE_STATEMENT, CLOB, CONNECTION, DATA_SOURCE, DATABASE_META_DATA, PARAMETER_META_DATA, PREPARED_STATEMENT, RESULT_SET, RESULT_SET_META_DATA, SAVEPOINT, SQL_EXCEPTION, STATEMENT, trace, XA_DATA_SOURCE, XA_RESOURCE, XID
 
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
 
Method Summary
 void addBatch(java.lang.String sql)
          Adds a statement to the batch.
 void cancel()
          Cancels a currently running statement.
protected  boolean checkClosed(boolean write)
          INTERNAL.
 void clearBatch()
          Clears the batch.
 void clearWarnings()
          Clears all warnings.
 void close()
          Closes this statement.
protected  void closeOldResultSet()
          INTERNAL.
 boolean execute(java.lang.String sql)
          Executes an arbitrary statement.
 boolean execute(java.lang.String sql, int autoGeneratedKeys)
          Executes a statement and returns the update count.
 boolean execute(java.lang.String sql, int[] columnIndexes)
          Executes a statement and returns the update count.
 boolean execute(java.lang.String sql, java.lang.String[] columnNames)
          Executes a statement and returns the update count.
 int[] executeBatch()
          Executes the batch.
 java.sql.ResultSet executeQuery(java.lang.String sql)
          Executes a query (select statement) and returns the result set.
 int executeUpdate(java.lang.String sql)
          Executes a statement (insert, update, delete, create, drop) and returns the update count.
 int executeUpdate(java.lang.String sql, int autoGeneratedKeys)
          Executes a statement and returns the update count.
 int executeUpdate(java.lang.String sql, int[] columnIndexes)
          Executes a statement and returns the update count.
 int executeUpdate(java.lang.String sql, java.lang.String[] columnNames)
          Executes a statement and returns the update count.
 java.sql.Connection getConnection()
          Returns the connection that created this object.
 int getFetchDirection()
          Gets the fetch direction.
 int getFetchSize()
          Gets the number of rows suggested to read in one step.
 java.sql.ResultSet getGeneratedKeys()
          Return a result set that contains the last generated auto-increment key for this connection, if there was one.
 int getLastExecutedCommandType()
          INTERNAL.
 int getMaxFieldSize()
          Gets the maximum number of bytes for a result set column.
 int getMaxRows()
          Gets the maximum number of rows for a ResultSet.
 boolean getMoreResults()
          Moves to the next result set - however there is always only one result set.
 boolean getMoreResults(int current)
          Move to the next result set.
 int getQueryTimeout()
          Gets the current query timeout in seconds.
 java.sql.ResultSet getResultSet()
          Returns the last result set produces by this statement.
 int getResultSetConcurrency()
          Gets the result set concurrency created by this object.
 int getResultSetHoldability()
          Gets the result set holdability.
 int getResultSetType()
          Gets the result set type.
 int getUpdateCount()
          Returns the last update count of this statement.
 java.sql.SQLWarning getWarnings()
          Gets the first warning reported by calls on this object.
 boolean isClosed()
          Returns whether this statement is closed.
 boolean isPoolable()
          Returns whether this object is poolable.
 void setCursorName(java.lang.String name)
          Sets the name of the cursor.
 void setEscapeProcessing(boolean enable)
          Enables or disables processing or JDBC escape syntax.
protected  void setExecutingStatement(CommandInterface c)
          INTERNAL.
 void setFetchDirection(int direction)
          Sets the fetch direction.
 void setFetchSize(int rows)
          Sets the number of rows suggested to read in one step.
 void setMaxFieldSize(int max)
          Sets the maximum number of bytes for a result set column.
 void setMaxRows(int maxRows)
          Gets the maximum number of rows for a ResultSet.
 void setPoolable(boolean poolable)
          Requests that this object should be pooled or not.
 void setQueryTimeout(int seconds)
          Sets the current query timeout in seconds.
 java.lang.String toString()
          INTERNAL
 
Methods inherited from class org.h2.message.TraceObject
debugCode, debugCodeAssign, debugCodeCall, debugCodeCall, debugCodeCall, getNextId, getTrace, getTraceId, getTraceObjectName, isDebugEnabled, isInfoEnabled, logAndConvert, quote, quoteArray, quoteBigDecimal, quoteBytes, quoteDate, quoteIntArray, quoteMap, quoteTime, quoteTimestamp, setTrace, unsupported
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

conn

protected JdbcConnection conn

session

protected SessionInterface session

resultSet

protected JdbcResultSet resultSet

maxRows

protected int maxRows

fetchSize

protected int fetchSize

updateCount

protected int updateCount

resultSetType

protected final int resultSetType

resultSetConcurrency

protected final int resultSetConcurrency

closedByResultSet

protected boolean closedByResultSet
Method Detail

executeQuery

public java.sql.ResultSet executeQuery(java.lang.String sql)
                                throws java.sql.SQLException
Executes a query (select statement) and returns the result set. If another result set exists for this statement, this will be closed (even if this statement fails).

Specified by:
executeQuery in interface java.sql.Statement
Parameters:
sql - the SQL statement to execute
Returns:
the result set
Throws:
java.sql.SQLException

executeUpdate

public int executeUpdate(java.lang.String sql)
                  throws java.sql.SQLException
Executes a statement (insert, update, delete, create, drop) and returns the update count. If another result set exists for this statement, this will be closed (even if this statement fails). If auto commit is on, this statement will be committed. If the statement is a DDL statement (create, drop, alter) and does not throw an exception, the current transaction (if any) is committed after executing the statement.

Specified by:
executeUpdate in interface java.sql.Statement
Parameters:
sql - the SQL statement
Returns:
the update count (number of row affected by an insert, update or delete, or 0 if no rows or the statement was a create, drop, commit or rollback)
Throws:
java.sql.SQLException - if a database error occurred or a select statement was executed

execute

public boolean execute(java.lang.String sql)
                throws java.sql.SQLException
Executes an arbitrary statement. If another result set exists for this statement, this will be closed (even if this statement fails). If the statement is a create or drop and does not throw an exception, the current transaction (if any) is committed after executing the statement. If auto commit is on, and the statement is not a select, this statement will be committed.

Specified by:
execute in interface java.sql.Statement
Parameters:
sql - the SQL statement to execute
Returns:
true if a result set is available, false if not
Throws:
java.sql.SQLException

getResultSet

public java.sql.ResultSet getResultSet()
                                throws java.sql.SQLException
Returns the last result set produces by this statement.

Specified by:
getResultSet in interface java.sql.Statement
Returns:
the result set
Throws:
java.sql.SQLException

getUpdateCount

public int getUpdateCount()
                   throws java.sql.SQLException
Returns the last update count of this statement.

Specified by:
getUpdateCount in interface java.sql.Statement
Returns:
the update count (number of row affected by an insert, update or delete, or 0 if no rows or the statement was a create, drop, commit or rollback; -1 if the statement was a select).
Throws:
java.sql.SQLException - if this object is closed or invalid

close

public void close()
           throws java.sql.SQLException
Closes this statement. All result sets that where created by this statement become invalid after calling this method.

Specified by:
close in interface java.sql.Statement
Throws:
java.sql.SQLException

getConnection

public java.sql.Connection getConnection()
Returns the connection that created this object.

Specified by:
getConnection in interface java.sql.Statement
Returns:
the connection

getWarnings

public java.sql.SQLWarning getWarnings()
                                throws java.sql.SQLException
Gets the first warning reported by calls on this object. This driver does not support warnings, and will always return null.

Specified by:
getWarnings in interface java.sql.Statement
Returns:
null
Throws:
java.sql.SQLException

clearWarnings

public void clearWarnings()
                   throws java.sql.SQLException
Clears all warnings. As this driver does not support warnings, this call is ignored.

Specified by:
clearWarnings in interface java.sql.Statement
Throws:
java.sql.SQLException

getMoreResults

public boolean getMoreResults()
                       throws java.sql.SQLException
Moves to the next result set - however there is always only one result set. This call also closes the current result set (if there is one). Returns true if there is a next result set (that means - it always returns false).

Specified by:
getMoreResults in interface java.sql.Statement
Returns:
false
Throws:
java.sql.SQLException - if this object is closed.

setCursorName

public void setCursorName(java.lang.String name)
                   throws java.sql.SQLException
Sets the name of the cursor. This call is ignored.

Specified by:
setCursorName in interface java.sql.Statement
Parameters:
name - ignored
Throws:
java.sql.SQLException - if this object is closed

setFetchDirection

public void setFetchDirection(int direction)
                       throws java.sql.SQLException
Sets the fetch direction. This call is ignored by this driver.

Specified by:
setFetchDirection in interface java.sql.Statement
Parameters:
direction - ignored
Throws:
java.sql.SQLException - if this object is closed

getFetchDirection

public int getFetchDirection()
                      throws java.sql.SQLException
Gets the fetch direction.

Specified by:
getFetchDirection in interface java.sql.Statement
Returns:
FETCH_FORWARD
Throws:
java.sql.SQLException - if this object is closed

getMaxRows

public int getMaxRows()
               throws java.sql.SQLException
Gets the maximum number of rows for a ResultSet.

Specified by:
getMaxRows in interface java.sql.Statement
Returns:
the number of rows where 0 means no limit
Throws:
java.sql.SQLException - if this object is closed

setMaxRows

public void setMaxRows(int maxRows)
                throws java.sql.SQLException
Gets the maximum number of rows for a ResultSet.

Specified by:
setMaxRows in interface java.sql.Statement
Parameters:
maxRows - the number of rows where 0 means no limit
Throws:
java.sql.SQLException - if this object is closed

setFetchSize

public void setFetchSize(int rows)
                  throws java.sql.SQLException
Sets the number of rows suggested to read in one step. This value cannot be higher than the maximum rows (setMaxRows) set by the statement or prepared statement, otherwise an exception is throws. Setting the value to 0 will set the default value. The default value can be changed using the system property h2.serverResultSetFetchSize.

Specified by:
setFetchSize in interface java.sql.Statement
Parameters:
rows - the number of rows
Throws:
java.sql.SQLException - if this object is closed

getFetchSize

public int getFetchSize()
                 throws java.sql.SQLException
Gets the number of rows suggested to read in one step.

Specified by:
getFetchSize in interface java.sql.Statement
Returns:
the current fetch size
Throws:
java.sql.SQLException - if this object is closed

getResultSetConcurrency

public int getResultSetConcurrency()
                            throws java.sql.SQLException
Gets the result set concurrency created by this object.

Specified by:
getResultSetConcurrency in interface java.sql.Statement
Returns:
the concurrency
Throws:
java.sql.SQLException

getResultSetType

public int getResultSetType()
                     throws java.sql.SQLException
Gets the result set type.

Specified by:
getResultSetType in interface java.sql.Statement
Returns:
the type
Throws:
java.sql.SQLException - if this object is closed

getMaxFieldSize

public int getMaxFieldSize()
                    throws java.sql.SQLException
Gets the maximum number of bytes for a result set column.

Specified by:
getMaxFieldSize in interface java.sql.Statement
Returns:
always 0 for no limit
Throws:
java.sql.SQLException - if this object is closed

setMaxFieldSize

public void setMaxFieldSize(int max)
                     throws java.sql.SQLException
Sets the maximum number of bytes for a result set column. This method does currently do nothing for this driver.

Specified by:
setMaxFieldSize in interface java.sql.Statement
Parameters:
max - the maximum size - ignored
Throws:
java.sql.SQLException - if this object is closed

setEscapeProcessing

public void setEscapeProcessing(boolean enable)
                         throws java.sql.SQLException
Enables or disables processing or JDBC escape syntax. See also Connection.nativeSQL.

Specified by:
setEscapeProcessing in interface java.sql.Statement
Parameters:
enable - - true (default) or false (no conversion is attempted)
Throws:
java.sql.SQLException - if this object is closed

cancel

public void cancel()
            throws java.sql.SQLException
Cancels a currently running statement. This method must be called from within another thread than the execute method.

Specified by:
cancel in interface java.sql.Statement
Throws:
java.sql.SQLException - if this object is closed

getQueryTimeout

public int getQueryTimeout()
                    throws java.sql.SQLException
Gets the current query timeout in seconds. This method will return 0 if no query timeout is set. The result is rounded to the next second.

Specified by:
getQueryTimeout in interface java.sql.Statement
Returns:
the timeout in seconds
Throws:
java.sql.SQLException - if this object is closed

setQueryTimeout

public void setQueryTimeout(int seconds)
                     throws java.sql.SQLException
Sets the current query timeout in seconds. Calling this method will commit an open transaction, even if the value is the same as before. Changing the value will affect all statements of this connection. This method does not commit a transaction, and rolling back a transaction does not affect this setting.

Specified by:
setQueryTimeout in interface java.sql.Statement
Parameters:
seconds - the timeout in seconds - 0 means no timeout, values smaller 0 will throw an exception
Throws:
java.sql.SQLException - if this object is closed

addBatch

public void addBatch(java.lang.String sql)
              throws java.sql.SQLException
Adds a statement to the batch.

Specified by:
addBatch in interface java.sql.Statement
Parameters:
sql - the SQL statement
Throws:
java.sql.SQLException

clearBatch

public void clearBatch()
                throws java.sql.SQLException
Clears the batch.

Specified by:
clearBatch in interface java.sql.Statement
Throws:
java.sql.SQLException

executeBatch

public int[] executeBatch()
                   throws java.sql.SQLException
Executes the batch.

Specified by:
executeBatch in interface java.sql.Statement
Returns:
the array of update counts
Throws:
java.sql.SQLException

getGeneratedKeys

public java.sql.ResultSet getGeneratedKeys()
                                    throws java.sql.SQLException
Return a result set that contains the last generated auto-increment key for this connection, if there was one. If no key was generated by the last modification statement, then an empty result set is returned.

Specified by:
getGeneratedKeys in interface java.sql.Statement
Returns:
the result set with one row and one column containing the key
Throws:
java.sql.SQLException - if this object is closed

getMoreResults

public boolean getMoreResults(int current)
                       throws java.sql.SQLException
Move to the next result set. This method always returns false.

Specified by:
getMoreResults in interface java.sql.Statement
Parameters:
current - Statement.CLOSE_CURRENT_RESULT, Statement.KEEP_CURRENT_RESULT, or Statement.CLOSE_ALL_RESULTS
Returns:
false
Throws:
java.sql.SQLException

executeUpdate

public int executeUpdate(java.lang.String sql,
                         int autoGeneratedKeys)
                  throws java.sql.SQLException
Executes a statement and returns the update count. This method just calls executeUpdate(String sql) internally. The method getGeneratedKeys supports at most one columns and row.

Specified by:
executeUpdate in interface java.sql.Statement
Parameters:
sql - the SQL statement
autoGeneratedKeys - ignored
Returns:
the update count (number of row affected by an insert, update or delete, or 0 if no rows or the statement was a create, drop, commit or rollback)
Throws:
java.sql.SQLException - if a database error occurred or a select statement was executed

executeUpdate

public int executeUpdate(java.lang.String sql,
                         int[] columnIndexes)
                  throws java.sql.SQLException
Executes a statement and returns the update count. This method just calls executeUpdate(String sql) internally. The method getGeneratedKeys supports at most one columns and row.

Specified by:
executeUpdate in interface java.sql.Statement
Parameters:
sql - the SQL statement
columnIndexes - ignored
Returns:
the update count (number of row affected by an insert, update or delete, or 0 if no rows or the statement was a create, drop, commit or rollback)
Throws:
java.sql.SQLException - if a database error occurred or a select statement was executed

executeUpdate

public int executeUpdate(java.lang.String sql,
                         java.lang.String[] columnNames)
                  throws java.sql.SQLException
Executes a statement and returns the update count. This method just calls executeUpdate(String sql) internally. The method getGeneratedKeys supports at most one columns and row.

Specified by:
executeUpdate in interface java.sql.Statement
Parameters:
sql - the SQL statement
columnNames - ignored
Returns:
the update count (number of row affected by an insert, update or delete, or 0 if no rows or the statement was a create, drop, commit or rollback)
Throws:
java.sql.SQLException - if a database error occurred or a select statement was executed

execute

public boolean execute(java.lang.String sql,
                       int autoGeneratedKeys)
                throws java.sql.SQLException
Executes a statement and returns the update count. This method just calls execute(String sql) internally. The method getGeneratedKeys supports at most one columns and row.

Specified by:
execute in interface java.sql.Statement
Parameters:
sql - the SQL statement
autoGeneratedKeys - ignored
Returns:
the update count (number of row affected by an insert, update or delete, or 0 if no rows or the statement was a create, drop, commit or rollback)
Throws:
java.sql.SQLException - if a database error occurred or a select statement was executed

execute

public boolean execute(java.lang.String sql,
                       int[] columnIndexes)
                throws java.sql.SQLException
Executes a statement and returns the update count. This method just calls execute(String sql) internally. The method getGeneratedKeys supports at most one columns and row.

Specified by:
execute in interface java.sql.Statement
Parameters:
sql - the SQL statement
columnIndexes - ignored
Returns:
the update count (number of row affected by an insert, update or delete, or 0 if no rows or the statement was a create, drop, commit or rollback)
Throws:
java.sql.SQLException - if a database error occurred or a select statement was executed

execute

public boolean execute(java.lang.String sql,
                       java.lang.String[] columnNames)
                throws java.sql.SQLException
Executes a statement and returns the update count. This method just calls execute(String sql) internally. The method getGeneratedKeys supports at most one columns and row.

Specified by:
execute in interface java.sql.Statement
Parameters:
sql - the SQL statement
columnNames - ignored
Returns:
the update count (number of row affected by an insert, update or delete, or 0 if no rows or the statement was a create, drop, commit or rollback)
Throws:
java.sql.SQLException - if a database error occurred or a select statement was executed

getResultSetHoldability

public int getResultSetHoldability()
                            throws java.sql.SQLException
Gets the result set holdability.

Specified by:
getResultSetHoldability in interface java.sql.Statement
Returns:
the holdability
Throws:
java.sql.SQLException

checkClosed

protected boolean checkClosed(boolean write)
INTERNAL. Check if the statement is closed.

Parameters:
write - if the next operation is possibly writing
Returns:
true if a reconnect was required
Throws:
DbException - if it is closed

closeOldResultSet

protected void closeOldResultSet()
                          throws java.sql.SQLException
INTERNAL. Close and old result set if there is still one open.

Throws:
java.sql.SQLException

setExecutingStatement

protected void setExecutingStatement(CommandInterface c)
INTERNAL. Set the statement that is currently running.

Parameters:
c - the command

getLastExecutedCommandType

public int getLastExecutedCommandType()
INTERNAL. Get the command type of the last executed command.


isClosed

public boolean isClosed()
                 throws java.sql.SQLException
Returns whether this statement is closed.

Returns:
true if the statement is closed
Throws:
java.sql.SQLException

isPoolable

public boolean isPoolable()
Returns whether this object is poolable.

Returns:
false

setPoolable

public void setPoolable(boolean poolable)
Requests that this object should be pooled or not. This call is ignored.

Parameters:
poolable - the requested value

toString

public java.lang.String toString()
INTERNAL

Overrides:
toString in class java.lang.Object