File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java Micro Edition and the fly likes Palm + Database = ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Palm + Database = ??" Watch "Palm + Database = ??" New topic
Author

Palm + Database = ??

AJ Dussault
Ranch Hand

Joined: May 17, 2000
Posts: 53
Hi all!
I am writing a small program that creates a database, deletes, updates, adds, etc. I can create the database because I can see the file that gets created (something like Dababase_65xxx).
I try to add items to the database (right now I am adding records like {1,1,1,1} or {2,2,2,2} ). I don't get any errors when I do this, however when I try to get the number of records in the database, I am always getting -1.
I am reading Eric's book, and the two pages that describe how to do this seem pretty straight forward - yet it still looks like I have missed something.
Any thoughts??
aj
AJ Dussault
Ranch Hand

Joined: May 17, 2000
Posts: 53
Well, after some time well spent in front of my computer last night, I found out some interesting things about my little project.
1) db.addRecord(byte[]) does add a record - to the LAST element in the database. A file gets created that looks like database_65255.
2) any time a new call to addRecord is done, it seems, that the previously added record gets over written.
3) getNumberofRecords doesn't seem to work either - I ALWAYS get -1.
So, my next step was to play with this database_65255 file for a while. Like I said, everytime I did a db.addRecord(byte[]), this particular file got overwritten. Hmmmm, if that is always the LAST element, can I use setRecord(int row, byte[] data) to populate the database from the begining?? (Since, looking at the source, addRecord simply called setRecord with ENDOFDATABASE set as the row.) Sure enough, that worked fine. But I noticed a strange thing - for every unique row I added, I got a Database_x file created in my directory. Strange, I would have expected only ONE file that contains ALL of my data, not a file that contained one row each!
Everything else seemed to work - I can update specific rows, sift thru and find matching rows with a specified user input - but I still have all of these little files floating around out there - seems very messy to me.
One more thing - I tried to port my application to POSE and got a KVM error...UGH!
If anyone can give some insight at to how these palm databases are supposed to work with Java - I would REALLY appreciate it.
AJ
AJ Dussault
Ranch Hand

Joined: May 17, 2000
Posts: 53
Hey Gang!
Well, I never did get my project to work on my palm. However I did learn a few things that don't seem to be documented anywhere. If someone with more experience with Java and programming for the palm can comment on my findings, I will truely appreciate it.
1. Using the KVM/Palm Emulator to create databases on your pc doesn't seem to work exactly as documented. First of all, a database file does not get created. This wonderful little file has all sorts of interesting information about your database, like it's name, type, creator, NUMBEROFRECORDS (see a previous post), locationblocks (which contain locationID, uniqueID, and attributes about each of the records), etc.

2. Because this file doesn't exist, (remember this is on your pc) any other program that you write that creates its own database, will write all over your previous database. (what a mess) It doesn't matter that the database name and creatorID are different, since there is no database file.....
3. Database records do get created. They all get created with names like Database_0, Database_1, Database_2, etc. However, addRecord(data) will forever add record Database_65256 (last record in database) and not to the next available spot as I would have expected.(Remember, this is running on your pc.) deleteRecord(int) will delete a record. It is documented to work by tagging the record as deleted and 'moving' it to the end of the database to be used later to sync. On your pc - the record is just gone.
I am seriously thinking about extending this project for my master's thesis. However the Java API for Palm Database programming seems very limited to me with very little documentation concerning differences between running on a pc and a device.
I found a blurb on a palm users group that 3Com/Palm will not guarantee a program will work on their OS unless it is written using CodeWarrior. Anyone know anything about this?
....where ARE my C books?.....
Yes, I am going to redo this using C. The API is much broader and there is much more documentation out in the world about this.
I find it really hard to believe that there is no one on this site that hasn't run into this issue. If anyone has any information at all about this topic, even if it's another question, by all means ask. I would rather program this in my native 'language' (java) than try to think back to my c days...and this discussion would make a good starting point for my research!
Thanks,
AJ
PS. If I continue talking to myself, you'll start to think I am crazy.
[This message has been edited by AJ Dussault (edited March 09, 2001).]
Eric Giguere
Ranch Hand

Joined: Oct 25, 2000
Posts: 170
The basic problem is that the classes you're using are completely unsupported and quite lame to begin with. They just don't expose all the functionality you need to use Palm databases in a real fashion, they're just there as a demo for J2ME implementors. If you really need to do database stuff on the Palm you should either wait for the MIDP to arrive (this summer) or else switch to using something like IBM's J9 (which has full support for all PalmOS APIs) or esmertec's Jbed.

------------------
Eric Giguere
author of:
Java 2 Micro Edition : A Professional Developer's Guide
PalmTM Database Programming: The Complete Developer's Guide


Eric Giguere
Author/Co-Author of: Mobile Information Device Profile for Java 2 Micro Edition: Professional Developer's Guide, Java 2 Micro Edition: Professional Developer's Guide and PalmTM Database Programming: The Complete Developer's Guide
AJ Dussault
Ranch Hand

Joined: May 17, 2000
Posts: 53
Thanks Eric! I will check it out.
Chris Lee
Greenhorn

Joined: Mar 10, 2001
Posts: 5
Hello, I have been working on a j2me project for a wirless firm, but I am beginning to feel that j2me is not ready for serious application. I heard that Sun and Palm have stopped development for j2me, is that true? Will Sun ever ship MIDP for palm? Where can i find more information regarding MIDP development on palm?
Thank you
Liam Ireland
Greenhorn

Joined: Nov 19, 2001
Posts: 1
I am currently trying to figure out Palm databases for a project I'm doing but can't get any concrete helpful information or examples.............. If you could send me some sample code for creating a database and editing/adding/deleting etc. in a database I would really appreciate it. This has really put me to a halt in my project!!
Yours Hopefully,
Liam
Originally posted by AJ Dussault:
Hi all!
I am writing a small program that creates a database, deletes, updates, adds, etc. I can create the database because I can see the file that gets created (something like Dababase_65xxx).
I try to add items to the database (right now I am adding records like {1,1,1,1} or {2,2,2,2} ). I don't get any errors when I do this, however when I try to get the number of records in the database, I am always getting -1.
I am reading Eric's book, and the two pages that describe how to do this seem pretty straight forward - yet it still looks like I have missed something.
Any thoughts??
aj

liang gu
Ranch Hand

Joined: Nov 05, 2001
Posts: 89
I have the following code working on both the simulator and the Palm VIIx device.
import javax.microedition.rms.*;
import java.util.Enumeration;
import java.util.Vector;
import java.io.*;
public class ProductDB {
RecordStore recordStore = null;
public ProductDB() {}
// Open a record store with the given name
public ProductDB(String fileName) {
try {
recordStore =
RecordStore.openRecordStore(
fileName, true);
} catch(RecordStoreException rse) {
rse.printStackTrace();
}
}
// Close the record store
public void close()
throws RecordStoreNotOpenException,
RecordStoreException {
if (recordStore.getNumRecords() == 0) {
//if ( true) {
String fileName =
recordStore.getName();
recordStore.closeRecordStore();
recordStore.deleteRecordStore(fileName);
} else {
recordStore.closeRecordStore();
}
}
// Add a new record (Product)
// to the record store
public synchronized void
addNewProduct(String record) {
ByteArrayOutputStream baos = new
ByteArrayOutputStream();
DataOutputStream outputStream = new
DataOutputStream(baos);
try {
//every record starts with the # sign
outputStream.writeUTF("#" + record);
}
catch (IOException ioe) {
System.out.println(ioe);
ioe.printStackTrace();
}
byte[] b = baos.toByteArray();
try {
recordStore.addRecord(b,
0, b.length);
}
catch (RecordStoreException rse) {
System.out.println(rse);
rse.printStackTrace();
}
}
// Enumerate through the records.
public synchronized
RecordEnumeration enumerate()
throws RecordStoreNotOpenException {
return recordStore.enumerateRecords(
null, null, true);
}
public String getRecord(int recordNum){
String rec = null;
String ret = null;
try
{
//chop off the # sign at the beginning of the record
rec = new String (recordStore.getRecord(recordNum));
int index = rec.indexOf('#');
ret = rec.substring(index+1, rec.length());
}
catch (Exception ex) {}
return ret;
}
public boolean isEmpty() {
boolean empty = true;
try
{
if (recordStore.getNumRecords() != 0)
{
empty = false;
}
}
catch (RecordStoreNotOpenException ex) {}
return empty;
}
public int getSize() {
int size = 0;
try
{
size = recordStore.getSize();
}
catch (RecordStoreNotOpenException ex){}
return size;
}
}

Eugene Teo
Greenhorn

Joined: Nov 19, 2001
Posts: 3
liang gu, from your code, you are using the CLDC API and MIDP and you converted it using midp4palm1.0 for your palm? I am hesitating and wondering if I should develop palm applications this way or using the unsupported kvm/kWAT/etc (are they still using this?) Or should i wait for PDAP.
www.embedded.oti.com has been up and down most of the time, anyone has got a mirror for their VAME and the tools? No response from the webmaster.
Thanks
--
eMail: eugeneteo@eugeneteo.net
Eugene Teo
Greenhorn

Joined: Nov 19, 2001
Posts: 3
Hmm Eric says that a MIDP record store does map onto a Palm database, although the exact internal format used is unspecified. (from another thread)... So, Database Connectivity with Java for Palm is ok
Eugene
------------------
eMail: eugeneteo@eugeneteo.net
www: http://www.eugeneteo.net/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Palm + Database = ??