There are a few ways to do this, but I'll explain the recommended way:
First of all, a database is not "object oriented", so you should
forget about the concept of storing 'Mydata' in a single column, and
in your case (as in most cases) even in a single table.

For your case, you will need two tables (maybe more, I don't know what
fields you have in your Location class)
The first table (mydata) will have the following columns:
_id (of type INTEGER PRIMARY KEY AUTOINCREMENT)
name (of type STRING)
data (of type INTEGER)
location_id (of type INTEGER) (which is like a 'pointer' to the
corresponding entry in the 'locations' table)

The second table (locations) will have the following columns:
_id (of type INTEGER PRIMARY KEY AUTOINCREMENT)
(... more columns here as needed by your Location class ...).

When you store a single instance of Mydata to the database, you
basically add a new row to both of those tables.
Why did we have to divide it into two tables? That's called 'database
normalization', so Google it and read about it.

>From an object-oriented point of view, you also have a few options:
(Just naming a few)
1. Each class will contain its own SQL handling code - I personally
don't like this approach.
2. Each class will have a corresponding adapter class that will handle
the SQL for a given class (This is just a partial solution)
3. Have a 'DatabaseHelper' class that will contain all SQL related
code. (For your problem this is the best solution, in my opinion)
4. For larger scale applications, a combination of 2 and 3 might be
better (some would say 1 and 3).

Anyhow, take the time to research and gain some background knowledge
and perspective before you dive into the code.
Also, read about the SqliteOpenHelper class, and look at the Notepad
sample in the SDK.

Lior Gonnen
UltimateFaves / UltimateFavesPRO developer
http://ultimatefaves.wordpress.com/



On Nov 18, 8:06 am, naveenballa <[email protected]> wrote:
> i have a class like
> class Mydata{
> String name;
> int data;
> Location[] locarray;
>
> }
>
> List<Mydata> = new ArrayList<Mydata>( );
>
> can anyone tell me how to add the object of Mydata class to Sqlite
> Database column
>
> Thanks in advance

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to