Reputation: 559
I want to add a list of values of a variable size in a row of a single SQL database. As i understood from the following topic, it's not possible with a List<>
object:
How to add a list to a SQL database (using java)
But it works with a String, which is basically an object containing an array of char:
ContentValues values = new ContentValues();
values.put(MyDB.COLUMN_NAME, contact.getName());
mDb.insert(MyDB.TABLE_CONTACTS, null, values);
So is it possible to add an array of an other type (like double[] myList
, possibly contained in an object) in the database, the same way as we added TEXT?
I am using java on Android Studio.
Upvotes: 2
Views: 1317
Reputation: 97
I don't think its possible but you don't need that.
you cant save objects in Java and they save as a text so you can put that in the field as a string and read that in your java again. but the saving string is meaningless and you have to read it with java or do some scripting.
Upvotes: 3
Reputation: 16409
One option would be to convert your array/list to a JSON string and insert in the database. While reading the data, you can then parse it and create an array or a list.
Upvotes: 1