2

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.

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

4 Comments

right, it's a good idea, i keepit in mind! but JSON is not the best efficiency for storage and computation cost, I would prefer to keep it as long or int I could also devide each int into bytes and cast them in char, but i feel like there is an easier way to do it
So there is no way to store an integer array in a database cell?
Not in MySQL. Not sure about other databases.
Glad I could help. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.