Layout of the StaffList user interface is finished.
Now we add the Select bean and set up a database query.
Adding the Select bean
- From the Database category of the beans palette, select
a Select bean and drop it onto the free-form surface of the StaffList
composite. VisualAge for Java automatically assigns the name Select1 to
the newly dropped bean.
Setting up the database connection for the query
- Open the properties window for Select1.
- Click the value field for the query property. A small
button appears.
- Select the small button. The Query window appears.
- On the Connection page, select the New button to the right of
the Database Access Class field. A prompter window
appears.
- VisualAge for Java will eventually generate data access code into a
separate class that you specify at this point. Enter information about
the new data access class as follows:
- In the Package field, type DAStaffList
- In the Class name field, type Staffers
- Select OK to close the prompter window.
The Database Access Class field should now contain the value
DAStaffList.Staffers.
- Select the Add button to the right of the
Connections field. The Connections Alias Definitions window
appears.
- In the Connection name field, type staffnames
- To make sure the connection will be sound, select Test
Connection. If everything is set up correctly, the Message window
returns The connection is successful.
- Select OK to close the window.
VisualAge for Java generates code for the connection into the data access
class you specified. The Query window should now look like this:

Assembling the SQL statement
- Still in the Query window, select the SQL page. The first field,
Database Access Class, is already filled in.
- Select the Add button to the right of the SQL
field. The New SQL Specification window appears.
- Enter information as follows:
- In the Tables page of the SmartGuide, select the
xxx.STAFF table, where xxx is the default user ID
established when you installed DB2.
- In the Columns page, select the columns that you want included in the
query, as follows:
- In the Sort page, specify the primary sort key. From the Columns
list, select NAME and then Add.
- To see your query, select the SQL page. It should look something
like this:

- Select Finish.
VisualAge for Java closes the SmartGuide window, generates code for the SQL
query, and returns you to the Query window. At this point, the SQL page
of the Query window should look something like this:

Select OK to close the Query window and return to the properties
window for the Select bean:

Close the properties window and save your work.
