Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Online Training

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
 
Training Index

Introduction to the JavaBeans API, Magercise 11 Help
A JDBCTM Bean Database Manager

by John Zukowski, MageLang Institute

[Magercise 11 | API Docs | Short Course | Magercises]

Help is available for each task.

Task 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.


Essential properties would include:

  • driver
  • url
  • user
  • password
  • sql

Depending on your design, you could implement additional properties for handling the results from queries, and so on--whatever fits your design.

Task 2

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


Depending on your design, these methods could vary considerably, but would typically include:

  • parseUrl()
  • connectToDB()
  • closeDB()
  • executeSql()
  • formatResultSetOutput()

Task 3

Next, create a database and load it with data.


The skeleton code files include programs for building and loading a sample database from Chris Date's classic database text; see SuppliesAndParts*.java. Also, DatabaseTool.java is included for independently verifying the operation of your database. Of course, you can build and/or verify the database with your preferred database tools, for example, Cloudscape JBMS or Microsoft Access.

Task 4

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


Note that the return mechanics for executeQuery(), executeUpdate(), and execute() differ. Minimally, you could display the results of an SQL operation via a read-only property. A better design would include support for targets in which the results of a query are delivered via an event object, for example, DatabaseManagerEvent, which would require a listener interface such as DatabaseManagerListener with a notification method such as queryPerformed().

Task 5

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


Implementing a method such as DatabaseManager.printResult() facilitates command-line testing.

Task 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.


Return to Magercise 11

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


[ This page was updated: 27-Oct-99 ]

Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-99 Sun Microsystems, Inc.
All Rights Reserved. Legal Terms. Privacy Policy.