Basic resolving

This topic explores the basic resolver functionality provided by the JBCL. It extends the concepts explored in the "Querying a database" tutorial to the resolving phase where you save your changes back to the data source.

To step through this tutorial, use the files you created from the "Querying a database" tutorial, or start with the completed sample files for this tutorial. These files are located in the samples\borland\samples\tutorial\dataset\QueryProvide directory under the file name QueryProvide.jpr.

The "Querying a database" tutorial explored the providing phase where data is obtained from a data source. The tutorial instantiated a QueryDataSet and associated components, and displayed the data stored in the Local InterBase Server employee sample file in a grid. This topic expands that example by

If you prefer to review the source code for the completed tutorial, the completed project files are located in the samples/borland/samples/tutorial/dataset/BasicResolve directory of your JBuilder installation under the file name BasicResolve.jpr. The running application looks like this:

To create this application,

  1. Open the project file you created for the "Querying a database" tutorial by choosing File|Open/Create, and then browsing to that project. If you did not complete the tutorial, you can access the completed project files from the samples\borland\samples\tutorial\dataset\QueryProvide directory of your JBuilder installation.

    Note: You should make backup copies of these files before modifying them since other tutorials in this book use the "Querying a database" files as a starting point.

  2. Select the Frame file in the Navigation pane. Select the Design tab in the Content pane.

  3. Add a NavigatorControl component from the JBCL tab of the Component palette. Place it above the grid. You may want to resize the grid to make room for the navigator, or enlarge the panel and move components around to make room for it.

    In the Inspector, set the dataSet property of the NavigatorControl to the instantiated data set, queryDataSet1.

  4. Add a StatusBar control from the JBCL tab of the Component palette. Place it at the bottom of the application UI.

    In the Inspector, set the dataSet property of the StatusBar to the instantiated data set, queryDataSet1.

  5. Add a ButtonControl component from the JBCL tab of the Component palette. Set the button's label property to Save Changes. (See the finished application at the beginning of this tutorial for general placement of the controls in the UI.)

  6. Select the ButtonControl, then click the Events tab of the Inspector. Double-click the actionPerformed() method. This changes the focus of the AppBrowser from the UI Designer to the Source pane and displays the stub for the actionPerformed() method.

    Add the following code to the actionPerformed() method:

      try {
          database1.saveChanges(queryDataSet1);
          System.out.println("Save changes succeeded");
      }
      catch (Exception ex) {
    // displays the exception on the StatusBar if the application includes one,
    // or displays an error dialog if there isn't 
        DataSetException.handleException(ex);  }
    
    If you've used different names for the instances of the objects, for example, database1, replace them accordingly.

  7. Run the application by selecting Run|Run. The application compiles and displays in a separate window. Data is displayed in a grid, with a Save Changes button, the navigator, and a status bar that reports the current row position and row count.

    If errors are found, an error pane appears that indicates the line(s) where errors are found. The code of the custom button is the most likely source of errors, so check that the code above is correctly entered. Make corrections to this and other areas as necessary to run the application.

When you run the application, notice the following behavior:

Make changes to the data displayed in the grid by inserting, deleting, and updating data. You can save the changes back to the Local InterBase employee database choosing either,

Note: Because of data constraints on the employee table, the save operation may not succeed depending on the data you change. Since other edits may return errors, make changes only to the FIRST_NAME and LAST_NAME values in existing rows until you become more familiar with the constraints on this table. For more information, see Tips on using InterBase.

For a list of more advanced resolving topics, see Saving changes back to the data source.