Wizard API updated!
Tim Boudreau has released a new version of the Swing Wizard library (version 0.997) that fixes the WizardException bug reported in JavaWorld's recent Open Source Java Project profile. The article's examples have been reworked to test out the new, improved WizardException. Thanks, Tim, for this helpful fix!
Open Source Java Projects: The Wizard API

Newsletter sign-up

Sign up for our technology specific newsletters.

Enterprise Java
View all newsletters

Email Address:

Scale an application from 2 to 3 tiers with JDBC

Learn how we can use JDBC to convert our Forum server application into a middleware layer

Before we get started, you may want to review the Forum application that we created earlier this year. In part 1 we built the client application, and in part 2 we developed the client-side networking and the server. I'll wait here for you to finish.

The task at hand

Now that you're sufficiently refreshed, we're ready to move on. The first place to begin improving our Forum application is the backend, which in the original version is nothing more than a limited flat-file database. The backend needs to be re-architected to connect to a "real" database. The new architecture will be three-tiered.

Re-architecting the Forum's backend improves the application in three ways:

  • Functionality is expanded by putting a real database behind the application, which enables more advanced clients to access more granular information, such as Subject and Sender attributes, for each article. This new functionality will be exposed with new Forum 1.1 API calls.

  • The application can scale to the database's maximum, because multiple middleware servers can now process against the same database. Browser security restrictions on applets make it impossible for Web/applet servers to connect to a database tier residing on a host other than their originating host. As a result, this type of architecture is impossible with the 1.0 version, which is client/server.

  • JDK 1.0.2 clients can be migrated into future 1.1 clients. These "legacy" clients, which are supported by "legacy" browsers, don't have built-in support for JDK 1.1 features like JDBC, and have to communicate via sockets or URLs.



Why JDBC?
JDBC is Java's database API that adapts arbitrary SQL databases to Java and provides a common interface for using them. JDBC works by providing three Java interfaces -- Connection, Statement, and ResultSet -- which are implemented by vendor-specific drivers. The programmer just plugs in the correct driver and sends the correct SQL to access the database of his/her choice -- the rest of JDBC usage is essentially uniform.

For the purpose of this application, we use the simple message database structure, shown next, which we will access via JDBC calls to the Windows NT 4.0 machine that hosts it.



Thread Sender Subject Article


       


       


       


       




Message database

This database is a quasi-relational database comprised of a single table, Messages. It conforms to the first normal form requirements of flatness and atomicity of attributes, but doesn't have a real primary key. For that matter, it isn't optimized either; the database is just for demo purposes.

Migration process

Are you ready to move from Forum 1.0 to Forum 1.1? Well let's get going. We'll begin by extending the API to add a bit of new functionality, then we'll implement the classes.

Here's a complete listing of all the source code we'll use in this article.

Extending the API
The 1.0 version of Forum's API, as used by Forum and implemented in the ForumComm client communications library, looks like this:

Hashtable loadAllThreads () -- Loads all threads defined in server's config file.
Vector loadThreadArticles (String t) -- Loads all articles in thread t.
boolean postArticle (String art, String t) -- Posts article art to thread t.

1 | 2 |  Next >
Resources
  • Previous Step by Step articles