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. We'll expand this 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. Or, 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. Add a NavigatorControl component and 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.

  3. Add a StatusBar control at the bottom of the application UI.

  4. Add a ButtonControl component and set the button's text to Save changes. (See the finished application at the beginning of this tutorial for general placement of the controls in the UI.)

  5. Select the ButtonControl, then click the events tab of the Component 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.

  6. 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. 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, the save operation may not succeed depending on the data you change. Since other edits may return errors, we suggest you 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.

You've just completed a tutorial explaining the default data resolve logic. For a list of more advanced resolving topics, see Saving changes back to the data source.