This topic covers providing values to a column using a picklist to enter a new value to a column, and it also covers creating a lookup that will display values from another column.
This tutorial shows how to create a picklist that can be used to set the value of the JOB_COUNTRY column from the list of countries available in the COUNTRY table. When the user selects a country from the picklist, that selection is automatically written into the current field of the table. This project can be viewed as a completed application by running the sample project Picklist.jpr, located in the /samples/DataExpress/Picklist subdirectory of your JBuilder installation.
This application is primarily created in the designer.
Open the connection property editor for the Database component by selecting, then double-clicking the connection property ellipsis in the Inspector. Set the connection properties to the JDataStore sample employee table as follows. The Connection URL points to a specific installation location. If you have installed JBuilder to a different directory, point to the correct location for your installation.
Property name | Value |
Driver | com.borland.datastore.jdbc.DataStoreDriver |
URL | jdbc:borland:dslocal:/usr/local/jbuilder/samples/JDataStore/
datastores/employee.jds
The employee.jds database is located under the samples directory of your JBuilder installation, which may be different on your system. This sample has been modified to find the file on your system. |
Username | Enter your name |
Password | not required |
The connection dialog includes a Test Connection button. Click this button to check that the connection properties have been correctly set. Results of the connection attempt are displayed in the status area. When the connection is successful, click OK.
Select the query property of the QueryDataSet component in the Inspector, double-click its ellipsis to open the QueryDescriptor dialog, and set the following properties:
Property name | Value |
Database | database1 |
SQL Statement | SELECT * FROM EMPLOYEE |
Click Test Query to ensure that the query is runnable. When the status area indicates Success, click OK to close the dialog.
To view the data in your application we need to add some UI components and bind them to the data set. To do this,
The JdbNavToolBar will enable you to move quickly through the data set when the application is running, as well as provide a default mechanism for saving changes back to your data source.
Among other information, the status label displays information about the current record or current operation.
Scrolling behavior is not available by default in any Swing component or dbSwing extension, so, to get scrolling behavior, we add the scrollable Swing or dbSwing components to a JScrollPane or a TableScrollPane. TableScrollPane provides special capabilities to JdbTable over JScrollPane. See the dbSwing documentation for more information.
You'll notice that the designer displays live data at this point.
For this option | Make this choice |
---|---|
Database | database1 |
SQL Statement | select COUNTRY from COUNTRY |
Click Test Query. When successful, click OK.
Property name | Value |
Picklist/Lookup DataSet | queryDataSet2 |
queryDataSet2 | COUNTRY |
Data Type | STRING |
Display Column? | checked |
queryDataSet1 | JOB_COUNTRY |
Click OK.
queryDataSet2.open();
Click the Insert button on the toolbar. Enter a new record, using the picklist to enter the value for JOB_COUNTRY. When the application is running, you can insert a row into the table, and, when it you enter a value for the JOB_COUNTRY field, you can select it from the drop-down pick list. The country you select is automatically inserted into the JOB_COUNTRY field in the EMPLOYEE data set.
To remove a picklist,