Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Make Java DB Your Client-side Portable Database : Page 4

By embedding Java DB in your Java application, you provide a portable database that launches and shuts down as the application does. If that's not enough, you can create XML schemas on the fly using XML files and insert rows into a table without using SQL too.


advertisement

Running the Application

As DdlUtils is still in development and has no binary release as of the writing of this article, you can get the code from the repository and do a build (Method 2), or you can use the jars from the extjars folder in the code download (Method 1).

The following are the instructions for the two methods:

Method 1:

  1. Install the code download in your favorite C drive or D drive.
  2. Rename cp.bat_txt to cp.bat.
  3. Edit cp.bat and change <INSTALL_DIR>.
  4. Open a command prompt window and run cp.bat.
  5. Goto: <INSTALL_DIR>\demo.
  6. Compile: $> javac MySimpleApp.java.
  7. Run: $> java MySimpleApp DBSchema.xml.
Method 2:
  1. Download Java DB from developers.sun.com.
  2. Download DdlUtils from http://db.apache.org.
  3. As there is no binary distribution available at this time for DdlUtils, you have to download all Jakarta Commons packages from jakarta.apache.org/commons:
    • commons-beanutils.jar
    • commons-betwixt-0.7.jar
    • commons-collections-3.1.jar
    • commons-digester-1.7.jar
    • commons-lang-2.1.jar
    • commons-logging.jar
  4. Include all the packages in the class path to compile MySimpleApp.java (from the code download) and run.
When the application starts, it instantiates the database. It then reads the database schema from the XML file and creates the schema. Data related to two users is inserted using DynaBeans. The application has a user interface for capturing the username and password from the user and validates it against the password stored in the embedded database (see Figure 1).



Click to enlarge

Figure 1. Initial Screen Using tiger/singh or vijay/woods to Login

Upon successful login, the next screen provides a list of available famous golf courses on the left-hand side and a list of golf courses the user has played on the right-hand side (see Figure 2).

Click to enlarge

Figure 2. Golf Courses Listed on the Right Are Pulled from Java DB

The application reads the list of golf courses the user has played from the database while launching the screen in Figure 2. As the database is used in embedded mode, it will shut down when the application is terminated.

Think of the Possibilities

What can be accomplished with an embedded Java database is left to the imaginations of software architects and developers. I am sure that a few years from now we will see many Java DB-backed interactive applications with zero downtime. Currently, plans are in the works to use Java DB as a repository for office productivity documents in Microsoft Office and OpenOffice, and in many of the new breed of AJAX-driven offerings. More importantly, Java DB addresses many of the functionality problems for mobile applications such as data replication.



Raghu Donepudi, an independent contractor, currently is a technical manager for a federal government agency. He has a master's degree in Computer Science from Lamar University in Texas. He is a Sun-certified Java developer and the author of many software design techniques.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap