Adding and setting the Select bean

Layout of the StaffList user interface is finished. Now we add the Select bean and set up a database query.

Adding the Select bean

  1. From the Database category of the beans palette, select Select palette icon 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

  1. Open the properties window for Select1.
  2. Click the value field for the query property. A small button appears.
  3. Select the small button. The Query window appears.
  4. On the Connection page, select the New button to the right of the Database Access Class field. A prompter window appears.
  5. 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:

    The Database Access Class field should now contain the value DAStaffList.Staffers.

  6. Select the Add button to the right of the Connections field. The Connections Alias Definitions window appears.
  7. In the Connection name field, type staffnames
  8. 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.
  9. 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:
Connection page of Query window for Select bean

Assembling the SQL statement

  1. Still in the Query window, select the SQL page. The first field, Database Access Class, is already filled in.
  2. Select the Add button to the right of the SQL field. The New SQL Specification window appears.
  3. Enter information as follows:
  4. In the Tables page of the SmartGuide, select the xxx.STAFF table, where xxx is the default user ID established when you installed DB2.
  5. In the Columns page, select the columns that you want included in the query, as follows:
  6. In the Sort page, specify the primary sort key. From the Columns list, select NAME and then Add.
  7. To see your query, select the SQL page. It should look something like this:
    Finished query on SQL page of Query window for Select bean
  8. 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:
Finished SQL query for Select bean

Select OK to close the Query window and return to the properties window for the Select bean:
Property sheet for Select1, showing query property

Close the properties window and save your work.