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

Field Summary
protected  StatementAfterListener aStatementAfterListener
           
protected  StatementBeforeListener aStatementBeforeListener
           
private static java.lang.String copyright
           
protected  boolean executingSQL
           
protected  DatabaseConnection fieldConnection
           
protected  boolean fieldDistinctTypesEnabled
           
protected  boolean fieldExecuted
           
protected  StatementMetaData fieldMetaData
           
protected  boolean fieldReadOnly
           
protected  int fieldTimeout
           
protected  boolean fieldValidateLOBs
           
protected  DatabaseRow parameters
           
protected  java.beans.PropertyChangeSupport propertyChange
           
protected  DatabaseResultTable rt
           
(package private) static long serialVersionUID
           
 
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.
protected  void applyTimeout()
          This method calls setTimeout on the com.ibm.db.DatabaseResultTable using the value currently set for this Statement bean.
abstract  void cancelExecution()
          Cancels execution (in another thread) of the SQL statement associated with this Statement.
protected  boolean connect()
          Connects to the database if you are not already connected.
protected  void copyParameters(DatabaseRow newParms)
          This method was created by a SmartGuide.
abstract  void execute()
          Executes the SQL statement.
protected  void finalize()
          Code to perform when this object is garbage collected.
protected  void fireAboutToExecute(DataEvent event)
          Method to support listener events.
protected  void fireExecuted(DataEvent event)
          Method to support listener events.
 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.
protected  DatabaseRow getParameters()
          Returns a DatabaseRow object that contains the names and values of all of the parameters that have been defined for this statement.
 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.
protected static void handleSQLException(java.sql.SQLException ex)
          This method was created by a SmartGuide.
 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.
private  void readObject(java.io.ObjectInputStream in)
          This method was reads in the serialized object and restores the following static/transient fields: propertyChange - contains a reference to a PropertyChangeSupport instance.
 void removeStatementAfterListener(StatementAfterListener listener)
          Removes a listener to the StatementAfter event set.
 void removeStatementBeforeListener(StatementBeforeListener listener)
          Removes a listener to the StatementBefore event set.
protected static java.lang.String replaceHostVars(java.lang.String statement)
          This method was created by a SmartGuide.
 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
, clone, equals, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

fieldConnection

protected DatabaseConnection fieldConnection

fieldExecuted

protected boolean fieldExecuted

fieldMetaData

protected StatementMetaData fieldMetaData

fieldReadOnly

protected boolean fieldReadOnly

fieldDistinctTypesEnabled

protected boolean fieldDistinctTypesEnabled

fieldTimeout

protected int fieldTimeout

fieldValidateLOBs

protected boolean fieldValidateLOBs

parameters

protected DatabaseRow parameters

rt

protected transient DatabaseResultTable rt

executingSQL

protected transient boolean executingSQL

propertyChange

protected transient java.beans.PropertyChangeSupport propertyChange

aStatementBeforeListener

protected transient StatementBeforeListener aStatementBeforeListener

aStatementAfterListener

protected transient StatementAfterListener aStatementAfterListener

serialVersionUID

static final long serialVersionUID

copyright

private static final java.lang.String copyright
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)

applyTimeout

protected void applyTimeout()
                     throws DataException
This method calls setTimeout on the com.ibm.db.DatabaseResultTable using the value currently set for this Statement bean.

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

connect

protected boolean connect()
                   throws DataException
Connects to the database if you are not already connected. If connection is externally managed, just propagates autoCommit property value to existing external connection. Otherwise, if not already connected, calls the connect method of com.ibm.db.DatabaseConnection
Returns:
true if there is a connection established, else false.

copyParameters

protected void copyParameters(DatabaseRow newParms)
This method was created by a SmartGuide.
Returns:
COM.ibm.ivj.db.base.DatabaseRow

execute

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

finalize

protected void finalize()
                 throws java.lang.Throwable
Code to perform when this object is garbage collected. Any exception thrown by a finalize method causes the finalization to halt. But otherwise, it is ignored.
Overrides:
finalize in class java.lang.Object

fireAboutToExecute

protected void fireAboutToExecute(DataEvent event)
Method to support listener events.
Parameters:
event - DataEvent

fireExecuted

protected void fireExecuted(DataEvent event)
Method to support listener events.
Parameters:
event - DataEvent

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)

getParameters

protected DatabaseRow getParameters()
Returns a DatabaseRow object that contains the names and values of all of the parameters that have been defined for this statement.
Returns:
all of the parameter values

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)

handleSQLException

protected static void handleSQLException(java.sql.SQLException ex)
                                  throws DataException
This method was created by a SmartGuide.
Throws:
DataException - The exception description.

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)

readObject

private void readObject(java.io.ObjectInputStream in)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
This method was reads in the serialized object and restores the following static/transient fields: propertyChange - contains a reference to a PropertyChangeSupport instance.
Parameters:
in - ObjectInputStream

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)

replaceHostVars

protected static java.lang.String replaceHostVars(java.lang.String statement)
This method was created by a SmartGuide.

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()