com.ibm.db.beans
Class DBModify

java.lang.Object
  |
  +--com.ibm.db.beans.DBStatement
        |
        +--com.ibm.db.beans.DBModify
All Implemented Interfaces:
java.io.Serializable

public class DBModify
extends DBStatement

This class allows you to execute an SQL insert, update, or delete in a bean which exposes JDBC 2.0 RowSet functionality and adds its own useful functions.

The JDBC RowSet "wraps" a connection, a statement, and a result set as a bean, and provides properties, methods, and events for using them. The DBModify bean is for executing statements that do not return result sets. Therefore, it does not expose RowSet functionality for dealing with result sets. However, much of the RowSet interface deals with setting database connection properties, setting parameters, and executing the statement, and this function is exposed.

This class also adds function to get the update count from an insert, update, or delete.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.ibm.db.beans.DBStatement
LEVEL_CONNECTION, LEVEL_RESULTSET, LEVEL_STATEMENT, TRANSACTION_DEFAULT
 
Constructor Summary
DBModify()
          Default constructor for a DBModify bean.
 
Method Summary
 void addDBAfterListener(com.ibm.db.beans.DBAfterListener listener)
          Adds a listener to the DBAfter event set.
 void addDBBeforeListener(com.ibm.db.beans.DBBeforeListener listener)
          Adds a listener to the DBBefore event set.
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Adds a listener to the PropertyChange event set.
 void close()
          Releases the underlying database connection and statement immediately instead of waiting for this to happen when the object is finalized.
 void close(int resourceLevel)
          Releases the underlying database and JDBC resources immediately instead of waiting for this to happen when the object is finalized.
 void execute()
          Executes the SQL statement, connecting to the database if not already connected.
 int getUpdateCount()
          Returns either the row count for INSERT, UPDATE or DELETE statements; or 0 for SQL statements that return nothing.
 boolean isOpen()
          Returns true if the underlying java.sql.Connection and java.sql.Statement are open, otherwise returns false.
 boolean isOpen(int resourceLevel)
          Returns true if the JDBC resource at the specified level is open, otherwise returns false.
 void reExecute()
          Re-executes the statement.
 void removeDBAfterListener(com.ibm.db.beans.DBAfterListener listener)
          Removes a listener to the DBAfter event set.
 void removeDBBeforeListener(com.ibm.db.beans.DBBeforeListener listener)
          Removes a listener to the DBBefore event set.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Removes a listener to the PropertyChange event set.
 
Methods inherited from class com.ibm.db.beans.DBStatement
cancelAction, clearParameters, commit, findParameter, getAutoCommit, getCommand, getConnection, getConnectionSpec, getDataSourceName, getDriverName, getInitialContextFactory, getJspNullToken, getLogWriter, getParameter, getParameter, getParameterAsString, getParameterAsString, getParameterCount, getParameterMetaData, getParameterName, getPassword, getProviderUrl, getQueryTimeout, getTrace, getTransactionIsolation, getUrl, getUsername, isExecuted, isOptimizeConvertToString, isOptimizeForJsp, isOptimizeForNoListeners, rollback, setAutoCommit, setCommand, setConnection, setConnectionSpec, setDataSourceName, setDriverName, setInitialContextFactory, setJspNullToken, setLogWriter, setOptimizeConvertToString, setOptimizeForJsp, setOptimizeForNoListeners, setParameter, setParameter, setParameterFromString, setParameterFromString, setPassword, setProviderUrl, setQueryTimeout, setTrace, setTransactionIsolation, setUrl, setUsername, shareConnectionWith
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBModify

public DBModify()
Default constructor for a DBModify bean. This constructor also creates associated bean of type DBParameterMetaData.

Method Detail

addDBAfterListener

public void addDBAfterListener(com.ibm.db.beans.DBAfterListener listener)
Adds a listener to the DBAfter event set. DBAfter events occur after significant actions have been completed via the DBModify.

Specified by:
addDBAfterListener in class DBStatement
Parameters:
listener - DBAfterListener
See Also:
DBAfterListener, removeDBAfterListener(com.ibm.db.beans.DBAfterListener)

addDBBeforeListener

public void addDBBeforeListener(com.ibm.db.beans.DBBeforeListener listener)
Adds a listener to the DBBefore event set. DBBefore events occur before significant actions have been completed via the DBModify.

Specified by:
addDBBeforeListener in class DBStatement
Parameters:
listener - DBBeforeListener
See Also:
DBBeforeListener, removeDBBeforeListener(com.ibm.db.beans.DBBeforeListener)

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a listener to the PropertyChange event set.

Specified by:
addPropertyChangeListener in class DBStatement
Parameters:
listener - PropertyChangeListener
See Also:
removePropertyChangeListener(java.beans.PropertyChangeListener)

close

public void close()
           throws DBException,
                  java.sql.SQLException
Releases the underlying database connection and statement immediately instead of waiting for this to happen when the object is finalized. If autoCommit is false, you must explicitly do a commit or rollback before using the close method.

Specified by:
close in class DBStatement
Throws:
java.sql.SQLException - if a database access error occurs
DBException
See Also:
close(int), isOpen()

close

public void close(int resourceLevel)
           throws DBException,
                  java.sql.SQLException
Releases the underlying database and JDBC resources immediately instead of waiting for this to happen when the object is finalized.

The JDBC resources that may be released include the Statement, and the Connection. The value of the resourceLevel parameter determines which resources are released. If all resources, including the Connection, are released, and autoCommit is false, you must explicitly do a commit or rollback before using the close method.

Specified by:
close in class DBStatement
Parameters:
resourceLevel - LEVEL_STATEMENT indicates Statement resources should be released. LEVEL_CONNECTION indicates Connection and Statement resources should be released.
Throws:
DBException - invalidResourceLevel - if the resource level is not valid
java.sql.SQLException - if a database access error occurs
See Also:
close(), isOpen(int)

execute

public void execute()
             throws DBException,
                    java.sql.SQLException
Executes the SQL statement, connecting to the database if not already connected.

Specified by:
execute in class DBStatement
Throws:
DBException - badUidPwd - if incorrect Userid or password specified
DBException - noSQL - if the SQL statement is null
DBException - noTransactions - if database does not support transactions and autoCommit set to false
java.sql.SQLException - - if a database access error occurred

getUpdateCount

public int getUpdateCount()
Returns either the row count for INSERT, UPDATE or DELETE statements; or 0 for SQL statements that return nothing.

Returns:
int the number of rows affected by the statement

isOpen

public boolean isOpen()
               throws java.sql.SQLException
Returns true if the underlying java.sql.Connection and java.sql.Statement are open, otherwise returns false.

When isOpen returns false, it may be because the statement has not been executed, the close method has been invoked, or the bean has been serialized and then de-serialized.

Specified by:
isOpen in class DBStatement
Returns:
true if the bean is open, otherwise false.
java.sql.SQLException
See Also:
close()

isOpen

public boolean isOpen(int resourceLevel)
               throws DBException,
                      java.sql.SQLException
Returns true if the JDBC resource at the specified level is open, otherwise returns false.

If the resourceLevel is LEVEL_CONNECTION, a return value of true indicates that the Connection is open. If the resourceLevel is LEVEL_STATEMENT, a return value of true indicates that the Statement, and therefore also the Connection are open.

Specified by:
isOpen in class DBStatement
Parameters:
resourceLevel - A resource level: LEVEL_CONNECTION, LEVEL_STATEMENT.
Returns:
true if the JDBC resource at the specified level is open, otherwise false.
Throws:
DBException - invalidResourceLevel - if the resource level is not valid
java.sql.SQLException - if a database-access error occurs.
See Also:
close(int)

reExecute

public void reExecute()
               throws DBException,
                      java.sql.SQLException
Re-executes the statement. The DBModify must currently be open. Any changes you have made to statement parameters will take effect when the statement is re-executed. If you have changed the statement itself, that change will not take effect. (To make the latter change take effect, use the execute method.

Specified by:
reExecute in class DBStatement
Throws:
DBException - noActiveConnection - if no active connection exists
DBException - notOpen - if the statement is not open
java.sql.SQLException - - if a database access error occurred
See Also:
execute()

removeDBAfterListener

public void removeDBAfterListener(com.ibm.db.beans.DBAfterListener listener)
Removes a listener to the DBAfter event set. DBAfter events occur after significant actions have been completed via the DBSelect.

Specified by:
removeDBAfterListener in class DBStatement
Parameters:
listener - DBAfterListener
See Also:
DBAfterListener, addDBAfterListener(com.ibm.db.beans.DBAfterListener)

removeDBBeforeListener

public void removeDBBeforeListener(com.ibm.db.beans.DBBeforeListener listener)
Removes a listener to the DBBefore event set. DBBefore events occur before significant actions have been completed via the DBSelect.

Specified by:
removeDBBeforeListener in class DBStatement
Parameters:
listener - DBBeforeListener
See Also:
DBBeforeListener, addDBBeforeListener(com.ibm.db.beans.DBBeforeListener)

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a listener to the PropertyChange event set.

Overrides:
removePropertyChangeListener in class DBStatement
Parameters:
listener - PropertyChangeListener
See Also:
addPropertyChangeListener(java.beans.PropertyChangeListener)