Select Bean

The Select bean is a non-visual bean. Using the Select bean you can query a relational database. You can also use the result set that is returned to insert, update or delete a row the database.

The Select bean has a query property which specifies how to connect to database and defines an SQL statement. Other properties allow you to specify such things as when rows are fetched, how many at a time, and whether a database lock should be acquired and held for a row while it is the current row.

The Select bean provides a set of methods for relational database access. For example it provides an execute method to execute  the SQL statement, and an updateRow method to update a row in the database based on data in the current row of the result set. To access relational data using a Select bean, you connect an interface component to the Select bean. For example, you can make an event-to-method connection between the actionPerformed event for a button and the execute method of the Select bean. When the button is selected, the SQL statement specified in the query property executes.

When you execute an SQL statement using a Select bean, it returns a result set. Unlike the native Java interface to relational data (JDBC), the Select bean maintains rows of the result set in a memory cache where you can move back and forth among the rows. You can control how many rows are in the cache at one time or over time by setting Select bean properties that control memory management

When an SQL statement runs using a Select bean, the first row of the result set becomes the current row. If you move to another row, that row becomes the current row. Many of the Select bean methods operate on the current row of the result set; other methods allow you to move among the rows.

You can display data in the result set by making a property-to-property connection between the appropriate source property of the Select bean and an appropriate target property of an interface component such as a JTable or text field. For example, to display result set data in a tabular form, you can make a property-to property connection between the this property of the Select bean and the model property of the JTable.

You can also display result set data one row at a time. If you use the the SQL Assist SmartGuide to compose your SQL statement, VisualAge for Java will generate two bound properties for each data column in the result set. One property is the data column in its specified data type, the other is a string representation of the data column. Make a property-to-property connection between the String representation of each data column in the result set and the text property of a text field. The text fields will display the column values of the current row.

Inserting, updating and deleting data

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 and position to the desired row. Any changes made to rows in the cache are applied to the database as well:

There are various ways to use the methods for inserting, updating and deleting data. For example, one way to implement updates in a program is to make an event-to-code connection between an appropriate interface component, such as a button, and a method. This method would obtain the new value from an interface component such as a text field and then use a Select bean method to set the value of the column in the current row of the result set to this new value. The method would then use another Select bean method to update the row in the database with these values.

Memory Management

You can control how many rows are in the memory cache at one time or over time by setting expert properties of the Select bean. The properties determine:

The maximum number of rows that will be in the cache at one time is the least of:

If memory management is not critical to your program, you need not be concerned with these properties. By default, the cache size is not limited; rows are fetched one at a time (a packet size of 1); and all of the rows in the result set are fetched into the cache as soon as you run your query.


Connection Aliases and SQL Specifications
Parameterized SQL Statements
Modify Bean
ProcedureCall Bean
Selector Beans
Navigator Bean


Accessing Relational Data