Build a Text Database And Database Program

Introduction

You can build a simple, single table database directly from a text file. While you won't often need this, it will introduce some of the database components and text files are the least system specific of the database files.

The Text Database File

First create your table as a text file using Notepad (or Wordpad making sure to save as text only). Determine the number of columns and what you will use to separate them in the file. A delimiter in a text file is a character that is used to define the beginning and end of a string field. By default, the delimiter for string data types is a double quotation mark, and the separator is a tab. A separator in a text file is a character that is used for differentiating between column values. By default, the separator character is a tab (\t). For this example, the separator is a comma (,). When using other text files, modify these properties accordingly.

Enter the following just as it appears here.

1,"A"
2,"B"
3,"C"

This will be result in a table with three rows and two columns. The number of columns usually stays constant while the number of rows varies with the number of items in your database.

Build The Schema

Build a project, but uncheck the "Use Only JDK & Swing Classes" check box . Check only the center of the screen checkbox for the Frame. Enter the design pane for the main frame and change the bevelPanel1 layout to Border.



Next add a Navigation bar (NORTH) and status bar (SOUTH) from the dbSwing pallet.
Next add a TextDataFile to the DataAccess node in the design tree (see diagram at the right). Then add a TableDataSet in the same place and set its datafile property to textDataFile1.
Next add a TableScrollPane (CENTER) to the bevelPanel1 and add a jdbTable to the TableScrollPane (use the tree to make sure). Click on the jdbTable plus sign to expand the tree (see diagram at right). Click on the new column branch of the tree and your will see a short properties window for this column. Enter the caption you want at the head of the column, and click outside that text box.

You should now see the extended version of the properties box. Set the name and datatype properties.
Set the focusedDataSet for the navigation bar and the dataSet for the jdbTable to tableDataSet1. This ties the UI components to the data access components. At this point the data should appear in the window
When you run the program you will see this.

Complete Code

For complete code click here .