The Select and ProcedureCall beans provide methods that you can use to insert, update, and delete rows in a result set. To perform these operations you must first use a Select or ProcedureCall bean to retrieve one or more result sets. (A ProcedureCall bean can retrieve more than one result set at a time while a Select bean has only one result set.) You then apply the changes to the current row of the current result set.
Inserting data
Inserting data via a Select or ProcedureCall bean is a 3-step process. You must:
By coding a method
One way of accomplishing these tasks is to make an event-to-code connection between an appropriate interface component, such as a button, and a method. For example, you can make an event-to-code connection between the actionPerformed event for a button and a method which executes methods of the Select or ProcedureCall bean. In this method, include code that calls the newRow method to add the empty row, the setColumnValue method to provide one or more values, and the updateRow or any method that moves to a different row to trigger insertion of the new row into the database.
Without coding a method
If you prefer not to write a method, you can use connections to a DBNavigator bean and to an interface component where your data is displayed to accomplish the same thing.
To use the DBNavigator bean, create a property-to-property connection between the this
property of the Select bean or ProcedureCall bean and the model property of a DBNavigator
bean. The DBNavigator bean has an Insert button that adds a new empty row to the
current result set.
If your data is displayed in a JTable, when you enter a new value into a cell of the table, the value is automatically set in the corresponding row and column of the result set.
If your data is displayed one row at a time in other interface components, such as text fields, which you have connected to the bound column properties of the Select bean or ProcedureCall bean, you need to insure that any value you provide in the interface component gets propagated to the corresponding row and column of the result set. If the property of the interface component is bound, VisualAge for Java generates code to do the propagation. However, many properties of interface components, including the text property of a text field, are not bound. In this case, you must specify in the connection properties, an event to trigger the propagation of the updated value to the column property.
Finally, you can use the Next button of the DBNavigator bean (or any
other button on the DBNavigator that moves to another row) to trigger insertion of the new
row into the database. If your data is displayed in a JTable and you are using the row
selection mechanisms of the JTable to control the current row of the result set you can
click on another row to trigger insertion of the new row. Or you can make an
event-to-method connection between another interface component, such as a button, and the
updateRow method of the Select bean or ProcedureCall bean.
Updating data
Updating data via a Select or ProcedureCall bean is a 2-step process. You must:
By coding a method
One way of accomplishing these tasks is to make an event-to-code connection between an appropriate interface component, such as a button, and a method. For example, you can make an event-to-code connection between the actionPerformed event for a button and a method which executes methods of the Select bean or ProcedureCall bean. In this method, include code that calls the setColumnValue method to provide one or more values, and updateRow or any method that moves to a different row to trigger the update of the row in the database.
Without coding a method
If you prefer not to write a method, you can use connections to a DBNavigator bean and to an interface component where your data is displayed to accomplish the same thing.
If your data is displayed in a JTable, when you enter a new value into any cell of the table, the value is automatically set in the corresponding row and column of the result set.
If your data is displayed one row at a time in other interface components, such as text fields, which you have connected to the bound column properties of the Select bean or ProcedureCall bean, you need to insure that any value you provide in the interface component gets propagated to the corresponding row and column of the result set. If the property of the interface component is bound, VisualAge for Java generates code to do the propagation. However, many properties of interface components, including the text property of a text field, are not bound. In this case, you must specify in the connection properties, an event to trigger the propagation of the updated value to the column property.
Once your values have been set, you can use the Next button of an
associated DBNavigator bean (or any other button on the DBNavigator that moves to another
row) to trigger the update of the row in the database. If your data is displayed in a
JTable and you are using the row selection mechanisms of the JTable to control the current
row of the result set you can click on another row to trigger the update of the new row in
the database. Or you can make an event-to-method connection between another interface
component, such as a button, and the updateRow method of the Select bean or ProcedureCall
bean.
Deleting data
Deleting data via a Select or ProcedureCall bean is a 1-step process. You need only use the deleteRow method to delete the current row from the database.
The Delete button of an associated DBNavigator bean executes the deleteRow method.
If you are not using a DBNavigator with a Delete button, you can make an event-to-method
connection between another interface component, such as a button, and the deleteRow method
of the Select bean or ProcedureCall bean.
About Relational Database Access
Editing Select bean properties
Editing ProcedureCall bean properties
Adding the DBNavigator bean to the Visual Composition
Editor surface
Displaying and navigating a result set
Connecting beans
Data Access Beans