Consider the following code snippet to query SQLite database:
String[] result_columns = new String[] {KEY_ID, COL1, COL2};
Cursor allRows = myDatabase.query(true, DATABASE_TABLE, result_columns,
null, null, null, null, null, null);
Which of the following prints out the values of COL1 column correctly if the result is not empty?
- if (allRows.moveToFirst()) {
do {
System.out.println(allRows.getString(1));
}
while (allRows.moveToNext()); } - do {
System.out.println(allRows.getString(0));
}
while (allRows.moveToNext()); - if (allRows.moveToFirst()) { do {
System.out.println(allRows.getString(0));
}
while (allRows.moveToNext()); } - if (allRows!= null) { do {
System.out.println(allRows.getString(1));
}
while (!allRows.isNull()); }
Reveal Solution Next Question