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
When either the custom button or the navigator's Save button is pressed, the changes made to the data in the QueryDataSet are saved to the employee data file using the JBCL default query resolver.
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,
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.
Save changes
. (See the finished application at the beginning of this tutorial for general placement of the controls in the UI.)
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.
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.