Java Database

For part of my NOT DEFINED, I needed some simple database functionality for storage of information and retrieval from several Java applications. I really didn't want the complexity of installing a large database because the may eventually run on a very small Java capable processor board. I also didn't need the complex interface and high performance associated with a typical database.

I decide to write a simple Java class to provide the main read and write database functions required. In essence, it simply store name/value pairs to disk. In my case, the disk is a solid-state USB memory stick, to reduce power consumption and to avoid wear on the main hard disk in my Mini-ITX machine.

Methods

The Java source code is available on request.

boolean Write(String name, String value)

Writes a file to the 'database' with the filename of name.js and with some text containing the value in it. If name contains spaces, these are replaced with an underscore character.

Returns TRUE if successful.

String Read(String name)

If name contains spaces, these are replaced with an underscore character before attempting to red the value. Returns a string within the value stored for this named variable.

JavaScript Interface

The reason for storing variables in files with a .js extension is to support inclusion in static HTML pages. This allows static web pages to display database variables using the <SCRIPT> tag. As an example the database would have a file in it called 'Study_Temperature.js' and the contents of this file might be:

var Study_Temperature="43";

This would allow a static HTML page that needs to display the value of 'Study Temperature' stored in the database by including the following in the HTML header:

<SCRIPT Language="JavaScript" src="Study_Temperature.js"></SCRIPT>