t e m p o r a l 
 d o o r w a y 

TextDataBase Applet

 

The objective of this applet is to allow the user to access a database from a web server where no DBMS server process is allowed to run.

It was difficult to determine that this was even possible. Almost every Java reference discusses JDBC, but every example seems to use it to either access a local database from an application, or a remote database from a remote database server. Yet there are many web sites which could publish databases, if the requirement to have the database be provided by a DBMS server could be eliminated.

It turns out that it is not very hard to eliminate this requirement, at least for a simple text database.

Layout

This applet uses the simple GridLayout. This is not a very flexible layout manager, but for the purpose of this applet it is adequate.

Controls

This applet has a JBCL GridControl which is used to display the table contents, and a JBCL TextAreaControl which displays the Comment field of the current line. Sadly, the TextAreaControl does not seem to be terribly intelligent, and does not word wrap, but for the moment, it is "good enough".

Data Access

The applet uses a TextDataFile to access the data from the web server. The file is loaded by the openStream method of the java.net.URL class which is passed to File.load(). The TextDataFile is in turn used by a TableDataSet. A DataSetView mediates between the TableDataSet and the GridControl / TextAreaControl.

Source

package TextDatabaseAccess;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import borland.jbcl.layout.*;
import borland.jbcl.control.*;
import borland.jbcl.dataset.*;

public class UIApplet extends Applet
{
   GridLayout appletLayout = new GridLayout();
   boolean isStandalone = false;
   TextDataFile File = new TextDataFile();
   TableDataSet Table = new TableDataSet();
   DataSetView View = new DataSetView();
   GridControl Grid = new GridControl();
   Column ID = new Column();
   Column Name = new Column();
   Column Comment = new Column();
   TextAreaControl CommentMemoControl = new TextAreaControl();

   public String getParameter(String key, String def)
   {
      return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def);
   }

   public UIApplet()
   {
   }

   public void init()
   {
      try
      {
         jbInit();
      }
      catch (Exception e)
      {
         e.printStackTrace();
      }
   }

   private void jbInit() throws Exception
   {
      appletLayout.setVgap(3);
      appletLayout.setHgap(3);
      appletLayout.setRows(2);
      appletLayout.setColumns(1);

      File.setFileName("");
      File.setLoadOnOpen(false);

      Table.setDataFile(File);
      Table.setSchemaName("");

      ID.setCaption("ID");
      ID.setColumnName("ID");
      ID.setDataType(borland.jbcl.util.Variant.STRING);
      ID.setPreferredOrdinal(0);

      Name.setCaption("Name");
        Name.setColumnName("Name");
      Name.setDataType(borland.jbcl.util.Variant.STRING);
      Name.setPreferredOrdinal(1);

      Comment.setCaption("Comment");
      Comment.setColumnName("Comment");
      Comment.setDataType(borland.jbcl.util.Variant.STRING);
      Comment.setPreferredOrdinal(2);

      Table.setColumns(new Column[] {ID, Name, Comment});

      File.load(Table,new java.net.URL("http://www.temporaldoorway.com/workshop/jbuilder/textdata.txt").openStream(),null);

      View.setStorageDataSet(Table);

      Grid.setAutoAppend(true);
      Grid.setColumnCaptions(new String[] {"ID", "Name", "Comment"});
      Grid.setDataSet(View);

      CommentMemoControl.setColumnName("Comment");
      CommentMemoControl.setDataSet(View);
      CommentMemoControl.setText("CommentMemoControl");

      this.setLayout(appletLayout);

      this.add(Grid);
      this.add(CommentMemoControl, null);
   }

   public String getAppletInfo()
   {
      return "Applet Information";
   }
   
   public String[][] getParameterInfo()
   {
      return null;
   }
}

Comments

This applet predefines the metadata. Obviously, the metadata can be downloaded in a more sophisticated and general application.

Copyright © 2004 by Mark Cashman (unless otherwise indicated), All Rights Reserved