I want to store my Object to be stored in Sq lite Db and retreive it back programatically,I want to know how to insert a object in sqlite i.e how to insert into sqlite as blob object
1 Answers
There is a very similar question to one in the BB Java Developer forum here:
How-to-write-and-read-a-blob-object-in-Blackberry-Java
The same answer applies here - you have to serialize your Object into bytes and then write the bytes. There is official documentation for writing blob bytes here:
There is nothing to really help you with the problem of converting an Object to bytes and back in Blackberry Java. You have to do this yourself. And because there is no reflection, you have to create individual serialization and deSerialization methods for each Object.
I would suggest serializing to JSON format. Android folks have GSON that will do it for them, but in BlackBerry, you have to do it all yourself.
In fact the serialization process is very similar to what you would do if you had to send the Object to a Server using HTTP PUT. You would create a JSON String, that you would then add as Post Data. When creating a blob from a JSON String, you just convert the String to bytes (don't forget to use UTF-8 when converting to and from the bytes if you decide to use JSON).
There is a lot of information on the web about serializing objects, but you will spend a lot of time sorting out stuff that is useful in BlackBerry because it only implements J2ME.
There is a paper that discusses serialization and presents a couple of serialization options here: Recursive and non-recursive method to serialize object at J2ME As noted, I would not use the 'binary' approach used in the paper, I would use JSON. Then you can use the JSON parser to deSerialize.
If you are only doing this for and in one class, you can add the code in that class. If you are planning to continue this, you could think about creating an interface that serializable Objects implement, and then in your generic SQL processing you can write shared code to handle the Objects which implement that interface. Just a thought.

- 2,640
- 11
- 11