Database class in kjava
After several days of frustration, I am still not able to create a working Database in a Palm application. The following code is reduced to a real minimum:
File = new Database(FileType, CreatorID, Database.READWRITE);
if(!File.isOpen()) {
Database.create(0, "Name", CreatorID, FileType, false);
File = new Database(FileType, CreatorID, Database.READWRITE);
}
File.setRecord(0, "Text");
File.close();
After executing this code, the INFO display shows that the file has been created, but that it contains 0 records. This is confirmed when I try to read the file the next time round -- it is empty.
Nothing I have tried has actually written to the file. Has anyone got any ideas?
Thanks,
ATC
[784 byte] By [
atcertik] at [2007-9-26 11:22:20]

atcertik,
Close, but for a new record, use the addRecord method.
Use setRecord for updating existing records.
Also try to pass the record a byte array versus a string.
Also, if possible, drop the use of kJava and start to use MIDP with the Palm profile. kJava was never supported by Sun, and now that the Palm profile exists, you can be supported and also get debugging with Forte, etc.
Thanks for the input. I made a bit of an error when I streamlined the code for the example. In the real code, I did use a byte array to write the record. As for using addRecord, a look at the source reveals that this function simply calls setRecord using ENDOFDATABASE as the record number. Even if this worked (which it does not -- I've tried it), it would overwrite each subsequent record at the last position.
I'll definitely have a look at the Palm profile with MIDP, but in the meantime if you have any suggestions that will make this one run, I would still be interested.
Thanks again.