Question

In my j2me application, The RecordStore name is "UserAns", and the entered data is stored in the '0000003-User-Ans.db' file. I can fetch the data from '0000003-User-Ans.db' file and display it on Emulator. But when I run the application on device, then it can't display any data. So, how can I add '0000003-User-Ans.db' file into Application Jar File ?

Was it helpful?

Solution

RecordStore internals is device dependent. The .db file that works on emulator will not work on real devices.

However, you could store your initial data in a different format, say csv, for example, and have an import procedure running at the very first time the application is executed (your RecordStore will be empty then).

Update after comments

Let's say you only have one "table" to initiate: Product. With columns: id, name, price. And that there is a Product Java class with corresponding attributes. A csv sample would be

1, Pen, 1
2, Clip, 0.05
3, Eraser, 0.5

Have this content stored in a file inside the jar, for example, products.csv. Open this file and parse each line to create a Product instance. Convert each instance to a byte array and create a record entry for each of them.

Next time the application is initiated the RecordStore will not be empty and a Product instance can be created for each record found.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top