Answer the question
In order to leave comments, you need to log in
How to pull data from SQLITE database and populate two dimensional array with it in JAVA?
Good afternoon,
There is some data table "table" with ID and NAME elements.
How can I pull these values from the database into a two-dimensional array in JAVA?
Basically my example:
sumID= db.execSQL(SELECT sum(id) FROM table);
int arr[sumID][2];
arr = new int[sumID][sumID];
for (int i = 0; i <= sumID - 1; i++) {
arr[i][0]= // как вывести элемент id из bd?
arr[i][1]= //как вывести элемент name из bd?
}
Answer the question
In order to leave comments, you need to log in
in the base id is not necessarily sequential so the array is not suitable for you, use HashMap
Cursor c = db.query("table_name", null, null, null, null, null, null);
if(c!=null&&c. moveToFirst()){
do{
long id = c.getLong(c.getColumnIndexOrThrow ("_id"));
String name = c.getString(c.getColumnIndexOrThrow ("name"));
// добавляете в hashMap или куда вам удобнее
}while(c.moveToNext());
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question