tags:

views:

943

answers:

2

Is it possible to store user defined objects in a SQLite database from Android? For example: I am creating one class and I want to store that class object in the database. Is it possible? If it is, how to proceed? On the Blackberry platform, I am able to store objects directly in persistent objects. Is it possible to do this with SQLite and Android?

+3  A: 

You'll need to be able to serialize your object into a byte stream and then recreate your object from a byte stream.

Then, just store that byte stream in your db.

EDIT: Read this article to learn about serialization in Java. It caters to the subject in a much better way than I would be able to by just giving some code snippets.

Prashast
can u pls provide me some code snippet to do serialization of object.
Kumar
I edited the answer and give a link to an article which teaches you how to do object serialization.
Prashast
A: 

Not sure if Android will run the cPickle python module, but see this solution at SourceForge; perhaps change one line "import cPickle as yPickle" substituting pickle for cPickle under Jython:

y_serial.py module :: warehouse Python objects with SQLite

"Serialization + persistance :: in a few lines of code, compress and annotate Python objects into SQLite; then later retrieve them chronologically by keywords without any SQL. Most useful "standard" module for a database to store schema-less data."

http://yserial.sourceforge.net

code43