com.ibm.db
Class Statement

java.lang.Object
  |
  +--com.ibm.db.Statement
Direct Known Subclasses:
SelectStatement, SQLStatement

public abstract class Statement
extends java.lang.Object
implements java.io.Serializable

Statement is an abstract super class that represents an SQL statement.

See Also:
SelectStatement, SQLStatement, CallableStatement, Serialized Form

Constructor Summary
Statement()
          Constructs a new Statement.
 
Method Summary
 void addStatementAfterListener(StatementAfterListener listener)
          Adds a listener to the StatementAfter event set.
 void addStatementBeforeListener(StatementBeforeListener listener)
          Adds a listener to the StatementBefore event set.
abstract  void cancelExecution()
          Cancels execution (in another thread) of the SQL statement associated with this Statement.
abstract  void execute()
          Executes the SQL statement.
 DatabaseConnection getConnection()
          Returns the DatabaseConnection associated with this Statement.
 StatementMetaData getMetaData()
          Returns the StatementMetaData associated with the Statement.
 java.lang.Object getParameter(int parameterNumber)
          Returns the value of the parameter at the specified index.
 java.lang.Object getParameter(java.lang.String parameterName)
          Returns the value of the parameter with the specified name.
 java.lang.String getParameterToString(int parameterNumber)
          Returns the value of the parameter at the specified index as a String.
 java.lang.String getParameterToString(java.lang.String parameterName)
          Returns the value of the parameter with the specified name as a String.
 int getTimeout()
          Returns the number of seconds the JDBC driver will wait for this statement to execute.
 boolean isExecuted()
          Returns true if execute has been invoked for the Statement.
 boolean isReadOnly()
          Returns true if updates are disallowed even when the database would permit them.
 boolean isValidateLOBs()
          Returns true validates LOBs before they are returned from the cache.
 void removeStatementAfterListener(StatementAfterListener listener)
          Removes a listener to the StatementAfter event set.
 void removeStatementBeforeListener(StatementBeforeListener listener)
          Removes a listener to the StatementBefore event set.
 void setConnection(DatabaseConnection connection)
          Associates a DatabaseConnection with the Statement.
 void setMetaData(StatementMetaData metaData)
          Associates a StatementMetaData with the Statement.
 void setParameter(int parameterNumber, java.lang.Object aValue)
          Sets the parameter at the specified index to the specified value.
 void setParameter(java.lang.String parameterName, java.lang.Object aValue)
          Sets the parameter with the specified name to the specified value.
 void setParameterFromString(int parameterNumber, java.lang.String stringValue)
          Sets the parameter at the specified index to the specified value.
 void setParameterFromString(java.lang.String parameterName, java.lang.String stringValue)
          Sets the parameter with the specified name to the specified value.
 void setReadOnly(boolean aValue)
          If true, updates are disallowed even when the database would permit them.
 void setTimeout(int seconds)
          Sets the number of seconds the JDBC driver will wait for this statement to execute.
 void setValidateLOBs(boolean validateLOBs)
          If true, validates LOBs before they are returned from the cache.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Statement

public Statement()
Constructs a new Statement.
Method Detail

addStatementAfterListener

public void addStatementAfterListener(StatementAfterListener listener)
Adds a listener to the StatementAfter event set. StatementAfter events occur after statement-scoped actions have completed such as execute and refresh.
Parameters:
listener - StatementAfterListener
See Also:
StatementAfterListener, removeStatementAfterListener(com.ibm.db.StatementAfterListener)

addStatementBeforeListener

public void addStatementBeforeListener(StatementBeforeListener listener)
Adds a listener to the StatementBefore event set. StatementBefore events occur before statement-scoped actions such as execute and refresh.
Parameters:
listener - StatementBeforeListener
See Also:
StatementBeforeListener, removeStatementBeforeListener(com.ibm.db.StatementBeforeListener)

cancelExecution

public abstract void cancelExecution()
                              throws DataException
Cancels execution (in another thread) of the SQL statement associated with this Statement. See subclasses for implementation details.
Throws:
DataException - - if an error occurs

execute

public abstract void execute()
                      throws DataException
Executes the SQL statement. See subclasses for more detail.
Throws:
DataException - - if an error occurs

getConnection

public DatabaseConnection getConnection()
Returns the DatabaseConnection associated with this Statement.
Returns:
the associated DatabaseConnection
See Also:
setConnection(com.ibm.db.DatabaseConnection)

getMetaData

public StatementMetaData getMetaData()
Returns the StatementMetaData associated with the Statement.
Returns:
the associated StatementMetaData
See Also:
setMetaData(com.ibm.db.StatementMetaData)

getParameter

public java.lang.Object getParameter(int parameterNumber)
                              throws DataException
Returns the value of the parameter at the specified index. If the parameter value is null, a null is returned. The index of the first parameter is 1.
Parameters:
parameterNumber - index of the parameter
Returns:
the parameter value
Throws:
java.lang.IndexOutOfBoundsException - if the parameter index is not defined
DataException - sqlException - if an SQL Exception is raised (only thrown by CallableStatement)
See Also:
getParameterToString(int), setParameter(int, java.lang.Object)

getParameter

public java.lang.Object getParameter(java.lang.String parameterName)
                              throws DataException
Returns the value of the parameter with the specified name. If the parameter value is null, a null is returned.
Parameters:
parameterName - name of the parameter
Returns:
the parameter value
Throws:
java.lang.IndexOutOfBoundsException - if the parameter name is not defined
DataException - sqlException - if an SQL Exception is raised (only thrown by CallableStatement)
See Also:
getParameterToString(int), setParameter(int, java.lang.Object)

getParameterToString

public java.lang.String getParameterToString(int parameterNumber)
                                      throws DataException
Returns the value of the parameter at the specified index as a String. The value of the parameter is converted to a String before the value is returned. If the parameter value is null, a null is returned. The index of the first parameter is 1.
Parameters:
parameterNumber - index of the parameter
Returns:
value of the parameter as a String
Throws:
java.lang.IndexOutOfBoundsException - if the parameter index is not defined
DataException - sqlException - if an SQL Exception is raised (only thrown by CallableStatement)
See Also:
getParameter(int), setParameterFromString(int, java.lang.String)

getParameterToString

public java.lang.String getParameterToString(java.lang.String parameterName)
                                      throws DataException
Returns the value of the parameter with the specified name as a String. The value of the parameter is converted to a String before the value is returned. If the parameter value is null, a null is returned.
Parameters:
parameterName - name of the parameter
Returns:
value of the parameter as a String
Throws:
java.lang.IndexOutOfBoundsException - if the parameter name is not defined
DataException - sqlException - if an SQL Exception is raised (only thrown by CallableStatement)
See Also:
getParameter(int), setParameterFromString(int, java.lang.String)

getTimeout

public int getTimeout()
Returns the number of seconds the JDBC driver will wait for this statement to execute. If the limit is exceeded, a DataException is thrown by the execute method.
Returns:
the timeout limit in seconds; zero means unlimited
See Also:
setTimeout(int)

isExecuted

public boolean isExecuted()
Returns true if execute has been invoked for the Statement.
Returns:
true if execute has been invoked for the Statement, otherwise false.

isReadOnly

public boolean isReadOnly()
Returns true if updates are disallowed even when the database would permit them. Returns false if updates are allowed as long as the database will permit them.
Returns:
true if updates are disallowed, otherwise false.
See Also:
setReadOnly(boolean)

isValidateLOBs

public boolean isValidateLOBs()
Returns true validates LOBs before they are returned from the cache.
Returns:
true if LOBs will be validated, else false.
See Also:
setValidateLOBs(boolean)

removeStatementAfterListener

public void removeStatementAfterListener(StatementAfterListener listener)
Removes a listener to the StatementAfter event set. StatementAfter events occur after statement-scoped actions have completed, such as execute and refresh.
Parameters:
listener - StatementAfterListener
See Also:
StatementAfterListener, addStatementAfterListener(com.ibm.db.StatementAfterListener)

removeStatementBeforeListener

public void removeStatementBeforeListener(StatementBeforeListener listener)
Removes a listener to the StatementBefore event set. StatementBefore events occur before statement-scoped actions such as execute and refresh.
Parameters:
listener - StatementBeforeListener
See Also:
StatementBeforeListener, addStatementBeforeListener(com.ibm.db.StatementBeforeListener)

setConnection

public void setConnection(DatabaseConnection connection)
Associates a DatabaseConnection with the Statement.
Parameters:
connection - the associated DatabaseConnection
See Also:
getConnection()

setMetaData

public void setMetaData(StatementMetaData metaData)
Associates a StatementMetaData with the Statement.
Parameters:
metaData - the associated StatementMetaData
See Also:
getMetaData()

setParameter

public void setParameter(int parameterNumber,
                         java.lang.Object aValue)
                  throws DataException
Sets the parameter at the specified index to the specified value. To set a parameter value to null, pass null as the value. The index of the first parameter is 1.
Parameters:
parameterNumber - index of the parameter
aValue - parameter value
Throws:
java.lang.IndexOutOfBoundsException - if the parameter index is not defined
DataException - wrongObjectType - if the value does not match the object type of the parameter
See Also:
setParameterFromString(int, java.lang.String), getParameter(int)

setParameter

public void setParameter(java.lang.String parameterName,
                         java.lang.Object aValue)
                  throws DataException
Sets the parameter with the specified name to the specified value. To set a parameter value to null, pass null as the value.
Parameters:
parameterName - name of the parameter
aValue - parameter value
Throws:
java.lang.IndexOutOfBoundsException - if the parameter name is not defined
DataException - wrongObjectType - if the value does not match the object type of the parameter
See Also:
setParameterFromString(int, java.lang.String), getParameter(int)

setParameterFromString

public void setParameterFromString(int parameterNumber,
                                   java.lang.String stringValue)
                            throws DataException
Sets the parameter at the specified index to the specified value. The index of the first parameter is 1.

The stringValue is converted to the datatype associated with the parameter before the parameter is updated. To set a parameter value to null, pass null as the value. If the datatype is not String, you can also set a parameter value to null by passing a zero-length String as the value.

Parameters:
parameterNumber - index of the parameter
stringValue - parameter value as a String
Throws:
java.lang.IndexOutOfBoundsException - if the parameter index is not defined
DataException - wrongObjectType - if the value does not match the object type of the parameter
See Also:
setParameter(int, java.lang.Object), getParameterToString(int)

setParameterFromString

public void setParameterFromString(java.lang.String parameterName,
                                   java.lang.String stringValue)
                            throws DataException
Sets the parameter with the specified name to the specified value.

The stringValue is converted to the datatype associated with the parameter before the parameter is updated. To set a parameter value to null, pass null as the value. If the datatype is not String, you can also set a parameter value to null by passing a zero-length String as the value.

Parameters:
parameterName - name of the parameter
stringValue - parameter value as a String
Throws:
java.lang.IndexOutOfBoundsException - if the parameter name is not defined
DataException - wrongObjectType - if the value does not match the object type of the parameter
See Also:
setParameter(int, java.lang.Object), getParameterToString(int)

setReadOnly

public void setReadOnly(boolean aValue)
If true, updates are disallowed even when the database would permit them. If false, updates are allowed as long as the database will permit them. The default value is false.
Parameters:
aValue - true if updates are disallowed; false if updates are allowed.
See Also:
isReadOnly()

setTimeout

public void setTimeout(int seconds)
Sets the number of seconds the JDBC driver will wait for this statement to execute. If the limit is exceeded, a DataException is thrown by the execute method.
Parameters:
seconds - the new timeout limit in seconds; zero means unlimited
See Also:
getTimeout()

setValidateLOBs

public void setValidateLOBs(boolean validateLOBs)
If true, validates LOBs before they are returned from the cache. The LOB is validated by attempting to access the data referenced by the LOB that has been cached. If it is not successful, then a new LOB is obtained by refetching the column or parameter from the database.

See Also:
isValidateLOBs()