The Select bean provides methods that you can use to insert, update, and delete relational data. To perform these operations you must first use a Select bean to retrieve a result set. You then apply the changes to the current row of the result set, as indicated by the currentRow property of the Select bean.
To insert data, make an event-to-script connection between an appropriate interface component, such as a button, and a script. For example, you can make an event-to-script connection between the actionPerformed event for a button and a script. In the script include code that inserts the row in the result set, use the Select bean method newRow to insert the row; then use the setColumnValue method to provide the value for the insert. The row is inserted into the database when another row in the result set becomes the current row.
To update data, make an event-to-script connection between an appropriate interface component, such as a button, and a script. For example, you can make an event-to-script connection between the actionPerformed event for a button and a script. In the script include code that provides an input value for the update, you can use the setColumnValue method to provide the value; use the Select bean method updateRow to update the current row in the result set and in the database.
If you made a property-to-property connection between a column property (which is bound) and another property (which might not be bound), VisualAge for Java generates code to propagate the updated value of the bound column property. If the other property is bound, VisualAge for Java generates similar code to propagate the updated value to the column property. If the other property is not bound, you must specify in the connection properties, an event to trigger the propagation of the updated value to the column property. VisualAge for Java then generates code that calls the setColumn method to set the value in the result set when the event is triggered.
To delete data, make an event-to-method connection between an appropriate interface component, to the Select bean. For example, you can make an event-to-script connection between the actionPerformed event for a button and the deleteRow method of the Select bean. The deleteRow method deletes the current row in the result set and in the database.
You can use the DBNavigator bean to insert or delete data in a relational database. The DBNavigator bean provides a set of buttons that includes an Insert and Delete button. To use the DBNavigator bean, you create a property-to-property connection between the this property of the Select bean and the model property of the DBNavigator bean. The this property refers to the whole object of the Select bean. The model property specifies that the DBNavigator bean will navigate the associated Select bean. When selected, the Insert button in the DBNavigator bean invokes the newRow method of the Select bean. When selected, the Delete button in the DBNavigator bean invokes the deleteRow method of the Select bean.
You can also use the DBNavigator to update data in a relational database,
although there is no Update button provided by the DBNavigator. Change
the displayed value, as appropriate, in a interface component, such as a text
field, that is connected to the pertinent column value in the result
set. If the connection specifies an event to trigger the propagation of
the updated value, the value will be set in the result set. Then select
a DBNavigator button, such as Next or Last, that changes the currentRow
property value. The values of the current row in the result set are
updated in the database before the currentRow property value is
changed.
About Relational Database Access
Editing Select Bean Properties
Adding the DBNavigator Bean to the Visual Composition Editor Surface
Connecting Beans
Data Access Beans