|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.ibm.db.beans.DBStatement | +--com.ibm.db.beans.DBSelect | +--com.ibm.db.beans.DBProcedureCall
This class allows you to call a stored procedure and use any parameters or result sets it returns in a bean which exposes JDBC 2.0 RowSet functionality and adds its own useful functions for managing stored procedure results.
The JDBC RowSet "wraps" a connection, a statement, and a result set as a bean, and provides properties, methods, and events for using them. It does not currently define interfaces for getting output parameters or multiple result sets from stored procedures. That function is added by this bean.
The bean does not currently support getting stored procedure results which are update counts. Only stored procedure results which are result sets are supported.
This bean also has function (some of it inherited from DBSelect) to help with managing large result sets and to make it easy to use the bean in a graphical user interface. For example, it can fire PropertyChange events for dynamically generated bound "properties" corresponding to the parameters of the stored procedure. You can also connect this bean to the utility bean DBTableModel, which adapts it for use as the model of a javax.swing.JTable.
Field Summary |
---|
Fields inherited from class com.ibm.db.beans.DBSelect |
---|
DEFER_NOTHING, DEFER_WRITE_TO_DATABASE, DEFER_WRITE_TO_DATABASE_AND_ROW_NUMBER_CHANGE, FETCH_FORWARD, FETCH_REVERSE |
Fields inherited from class com.ibm.db.beans.DBStatement |
---|
LEVEL_CONNECTION, LEVEL_RESULTSET, LEVEL_STATEMENT, TRANSACTION_DEFAULT |
Constructor Summary | |
---|---|
DBProcedureCall()
Default constructor for a DBProcedureCall bean. |
Method Summary | |
---|---|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a listener to the PropertyChange event set. |
void |
clearMetaData()
Clears the descriptions of all result sets for this DBProcedureCall. |
com.ibm.db.beans.DBSelectMetaData |
createMetaData(int position)
Creates a new DBSelectMetaData object to describe the specified result set. |
int |
findColumn(java.lang.String columnName)
Maps the given column label to its column index. |
boolean |
firstResult()
Applies any changes in the current row of the current result set to the database, and then positions to the first result set. |
com.ibm.db.beans.DBSelectMetaData |
getMetaData(int position)
Gets the meta data describing the result set at the specified position. |
java.lang.Object |
getParameter(int position)
Gets the value of the parameter at the specified position. |
int |
getResult()
Gets the number of the result set to which you are currently positioned. |
int |
getResultCount()
Gets the number of result sets. |
boolean |
hasResult()
Returns true if the store procedure returns at least one result set; returns false otherwise. |
boolean |
isFetchAllResultsOnExecute()
Returns true if all result sets produced by this procedure call will be obtained immediately during the execute method. |
boolean |
isLastResult()
Returns true if the current result set is the last one fetched and either there are known to be no more result sets or the statement has been closed. |
boolean |
isOpen()
Returns true if the underlying RowSet is open, otherwise returns false. |
boolean |
lastResult()
Applies any changes in the current row of the current result set to the database, and then positions to the last result set. |
boolean |
nextResult()
Applies any changes in the current row of the current result set to the database, and then positions to the next result set. |
boolean |
previousResult()
Applies any changes in the current row of the current result set to the database, and then positions to the previous result set. |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a listener to the PropertyChange event set. |
void |
setFetchAllResultsOnExecute(boolean fetchAll)
If true, all result sets produced by this procedure call will be obtained immediately during the execute method. |
boolean |
setResult(int resultNumber)
Applies any changes in the current row of the current result set to the database, and then positions to the specified result set. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public DBProcedureCall()
Method Detail |
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
addPropertyChangeListener
in class DBSelect
listener
- PropertyChangeListenerremovePropertyChangeListener(java.beans.PropertyChangeListener)
public void clearMetaData() throws java.sql.SQLException
java.sql.SQLException
createMetaData(int)
public com.ibm.db.beans.DBSelectMetaData createMetaData(int position) throws DBException, java.sql.SQLException
If there was already a result set described at this position, its description is replaced with a new (empty) one.
There is no public constructor for a DBSelectMetaData object. This method is the only way to create one.
position
- the result number
DBException
java.sql.SQLException
getMetaData(int)
,
clearMetaData()
public int findColumn(java.lang.String columnName) throws DBException, java.sql.SQLException
findColumn
in class DBSelect
columnName
- the label of the column
DBException
- noCurrentResult
- if you are not positioned on a result set.
java.sql.SQLException
public boolean firstResult() throws DBException, java.sql.SQLException
If there are no result sets, a false is returned.
If the current row should be locked ( isLockRows
returns true),
the current row of the new current result set is locked in the database.
DBException
- notExecuted
- if statement has not been executed
DBException
- rowChanged
- if the current row cannot be updated because it cannot be found in the database
DBException
- rowNotFound
- if the lockRows property is true and the new current row cannot be locked
DBException
- sqlException
- if an SQLException occurred
java.sql.SQLException
setResult(int)
public com.ibm.db.beans.DBSelectMetaData getMetaData(int position) throws DBException, java.sql.SQLException
position
- the result set number
DBException
- resultNotDefined
- if no result set has been defined at this position
java.sql.SQLException
getMetaData(int)
,
DBStatement.getParameterMetaData()
public java.lang.Object getParameter(int position) throws DBException, java.sql.SQLException
If the parameter is an output or inout parameter, then the first time you use this method after executing the stored procedure, its value will be retrieved from the database. Both the JDBC Statement and Connection must be open for this to succeed. Otherwise an exception will occur. Before executing, or after executing and using this method once, the Statement and Connection need not be open, and the exception will not occur.
getParameter
in class DBStatement
position
- position of the parameter
DBException
- noSuchParm
- if the parameter is not defined
java.sql.SQLException
- - if a database access error occursDBStatement.getParameterAsString(int)
,
DBStatement.setParameter(int, Object)
public int getResult()
setResult(int)
public int getResultCount()
If you use this method before executing the stored procedure, it reflects only the meta data you have provided about the stored procedure. If you use it after executing, the number returned will be the greater of the number before executing and the number of result sets actually fetched so far. (There could be additional result sets not yet fetched.)
public boolean hasResult()
If you use this method before executing the stored procedure, it reflects only the meta data you have provided about the stored procedure.
public boolean isFetchAllResultsOnExecute()
Once all result sets have been obtained, it is not possible to fetch additional rows in any result set. Therefore, if your procedure produces multiple result sets, and you used the cacheLimit property to limit the number of rows initially fetched, you should set this property to false in order to fetch additional rows.
If you do not execute this method, the value defaults to true.
setFetchAllResultsOnExecute(boolean)
,
nextResult()
,
DBSelect.setCacheLimit(int)
public boolean isLastResult()
It cannot be known that there are no more result sets until you have tried to go past the last result set. Therefore, if you are on the last result set and have not tried to go past it, this method will return false.
If there are no result sets, the method will return false. If you wish to
test whether any result sets were obtained by executing the stored procedure,
use hasResult()
or getResultCount()
.
hasResult()
,
getResultCount()
public boolean isOpen() throws java.sql.SQLException
If you are positioned to a result set returned by the stored procedure, this method reports the status of that result set. Otherwise it reports the status of the JDBC Statement.
When isOpen
returns true, the database Connection,
Statement, and current ResultSet (if any) are all open,
and the RowSet is fully functional.
When isOpen
returns false, it may be because the
statement has not been executed, the result set you are positioned to
has been closed, or the DBProcedureCall bean has been serialized
and then de-serialized.
If you are positioned to a result set which is closed, you can scroll among any rows currently in the cache and you can even perform inserts, updates, and deletes, but you cannot fetch any additional rows.
isOpen
in class DBSelect
java.sql.SQLException
DBSelect.isOpen(int)
,
DBSelect.close()
public boolean lastResult() throws DBException, java.sql.SQLException
If there are no result sets, a false is returned.
If the current row should be locked ( isLockRows
returns true),
the current row of the new current result set is locked in the database.
DBException
- notExecuted
- if statement has not been executed
DBException
- rowChanged
- if the current row cannot be updated because it cannot be found in the database
DBException
- rowNotFound
- if the lockRows property is true and the new current row cannot be locked
DBException
- sqlException
- if an SQLException occurred
java.sql.SQLException
setResult(int)
public boolean nextResult() throws DBException, java.sql.SQLException
If the next result set has not already been fetched from the database, it is fetched.
If there is no next result set, a false is returned.
Your position does not change, and no exception is thrown.
Thus, if there are no result sets, or you are on the
last result set, repeatedly invoking this method has no effect.
For a discussion of when no more result sets can be fetched,
see the isLastResult
method.
If the current row should be locked ( isLockRows
returns true),
the current row of the new current result set is locked in the database.
DBException
- notExecuted
- if statement has not been executed
DBException
- rowChanged
- if the current row cannot be updated because it cannot be found in the database
DBException
- rowNotFound
- if the lockRows property is true and the new current row cannot be locked
java.sql.SQLException
- - if an SQLException occurredsetResult(int)
public boolean previousResult() throws DBException, java.sql.SQLException
If there is no previous result set, a false is returned. Your position does not change, and no exception is thrown. Thus, if there are no result sets, or you are on the first result set, repeatedly invoking this method has no effect.
If the current row should be locked ( isLockRows
returns true),
the current row of the new current result set is locked in the database.
DBException
- notExecuted
- if statement has not been executed
DBException
- rowChanged
- if the current row cannot be updated because it cannot be found in the database
DBException
- rowNotFound
- if the lockRows property is true and the new current row cannot be locked
DBException
- sqlException
- if an SQLException occurred
java.sql.SQLException
setResult(int)
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
removePropertyChangeListener
in class DBSelect
listener
- PropertyChangeListeneraddPropertyChangeListener(java.beans.PropertyChangeListener)
public void setFetchAllResultsOnExecute(boolean fetchAll)
Once all result sets have been obtained, it is not possible to fetch additional rows in any result set. Therefore, if your procedure produces multiple result sets, and you have limited the cache size of result sets via the cacheLimit property, you should set this property to false in order to fetch additional rows.
If you do not execute this method, the value defaults to true.
fetchAll
- true fetch all result sets during execute();
false fetch only the first result set during execute().
isFetchAllResultsOnExecute()
,
nextResult()
public boolean setResult(int resultNumber) throws DBException, java.sql.SQLException
If the specified result set has not yet been fetched, result sets are fetched until the specified result set is in the cache or no more result sets can be fetched. If no more result sets can be fetched, and the specified result set was not reached, a false is returned to indicate that the request could not be satisfied.
If the current row should be locked ( isLockRows
returns true),
the current row of the new current result set is locked in the database.
resultNumber
- index of the result set
DBException
- notExecuted
- if statement has not been executed
DBException
- rowChanged
- if the current row cannot be updated because it cannot be found in the database
DBException
- rowNotFound
- if the lockRows property is true and the new current row cannot be locked
java.sql.SQLException
- - if an SQLException occurredgetResult()
,
nextResult()
,
previousResult()
,
firstResult()
,
lastResult()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |