I often have a need for a small easy to use database so I decided to whip up a quick library for ISAM like database access. I have the basics working now and in a couple of days will be adding indexing using single and concatenated keys. Might also write a little database explorer in swing. A friend wants me to add network access to it as well.
I’m also using this project to learn a bit about NIO. The first version I’m working on now is all regular io package stuff. I will be converting it to NIO after it has all the features I want.
If anyone else has need for this sort of thing let me know and I’ll post the library up when it is finished.
If you haven’t used ISAM before setting up a database is very easy, mine is a little bit different from ISAM but has the same outcome:
//---------------------------------
// create the record format and add the coulmns you need
//---------------------------------
FixedRecordFormat format = new FixedRecordFormat();
format.addIntegerField(“ID”);
format.addStringField(“First Name”,30);
format.addStringField(“Last Name”,30);
//---------------------------------
// create the empty database files
//---------------------------------
String location = “\temp\mydatabase”;
FixedRecordFormatFile database = new FixedRecordFormatFile(location);
database.create();
database.close();
//---------------------------------
// add a few records
//---------------------------------
database.open(); // notice that once a database has been created you don’t have to set up the record format
Record rec = new Record(database.getFormat());
rec.setIntegerFieldValue(“ID”,1);
rec.setStringFieldValue(“First Name”,“Scott”);
rec.setStringFieldValue(“Last Name”,“Shaver”);
database.addRecord(rec);
rec.setIntegerFieldValue(“ID”,2);
rec.setStringFieldValue(“First Name”,“Bert”);
rec.setStringFieldValue(“Last Name”,“Shaver”);
database.addRecord(rec);
//---------------------------------
// other commands
//---------------------------------
database.rewind(); // set the current record position to the first record
database.setCurrentRecord(recIndex); // set a specific record position as the current record
database.nextRecord(); // move to the next record position
database.previousRecord(); // move to the previous record position
database.deleteRecord(); // delete the record at the current record position
database.writeRecord(recordToWrite); // write a recrod at the current record position
database.compact(); // remove any empty records from the database file
database.getRecordCount(); // find the total current capacity of the database file