Sun Java Solaris Communities My SDN Account Join SDN
 
Tutorials & Code Camps

Magercise 11 - A JDBC Bean Database Manager

 
Training Index



By John Zukowski, MageLang Institute

[Help | API Docs | Short Course | Magercises]

For this Magercise you use the BeanBox, or another IDE, to design and test a nongraphical JDBC Bean. The Bean makes a JDBC connection to a database server, after which it performs SQL operations as requested. You should design your Bean so that other users (programmers) can plug your JDBC Bean into their applications via an IDE.

Magercise 11 Prerequisites

Skeleton Code

Tasks

  1. The first task is to design and implement the DatabaseManager Bean with a no-argument constructor, plus access methods for properties for the typical configuration options and database interactions.

  2. Next, design and implement several methods that coordinate option processing with database connection and SQL operations:

  3. Next, create a database and load it with data.

  4. Design and implement a mechanism for displaying the data that's returned from a query, update, or general database operation.

  5. Create a separate test program (or add a main() to DatabaseManager.java) that tests the DatabaseManager Bean.

  6. If your executeSql() and connectToDB() are not no-argument methods with void returns, implement the appropriate control methods for point-and-click connection of command button actions to database operations, so that you can interact with a database from the BeanBox.

Where help exists, the task numbers above are linked to the step-by-step help page.

Solution Source

Demonstration

After loading the DatabaseManager Bean, it should appear in the palette, from where it can be selected and instantiated on the worksheet:

In this case, the worksheet contains a nongraphical DatabaseManager Bean and command buttons for connecting to and submitting a query, plus a TextArea specialization for displaying the results of a query.

The property sheet displays the published properties:

Magercise 12
Short Course
About This Short Course

Copyright © 1998-1999 MageLang Institute. All Rights Reserved.