I have a cursor that I'm filling from the SQLite database, but apparently it's empty, I want to show it in the console using a log.
cursor=db.obtenerSaldoClienteFavor(idClienteA);
This is my cursor, thank you very much
I have a cursor that I'm filling from the SQLite database, but apparently it's empty, I want to show it in the console using a log.
cursor=db.obtenerSaldoClienteFavor(idClienteA);
This is my cursor, thank you very much
cursor.moveToFirst()
. Log.v("Cursor Object", DatabaseUtils.dumpCursorToString(cursor))
To do this you need to know the names of the fields and the data type of the fields that your query gets, since based on this you will determine which method you will use to obtain the value, for example:
getString (int columnIndex) Returns the value of the requested column like a chain.
getInt (int columnIndex) Returns the value of the requested column as an int.
getLong (int columnIndex) Returns the value of the requested column like a long one.
getDouble (int columnIndex) Returns the value of the requested column as double.
getBlob (int columnIndex) Returns the value of the requested column as a byte array.
and using a loop using while
, you can get the values using the getColumnIndex () which is where you would specify the name of the field.
Assuming that your query gets the fields idCliente
and nombre
, this would be an example:
Cursor cursor = db.obtenerSaldoClienteFavor(idClienteA);
while (cursor.moveToNext()) {
Log.i("Dato cursor", "idCliente " + cursor.getInt(cursor.getColumnIndex("idCliente")) + " nombre: " + cursor.getString(cursor.getColumnIndex("nombre")));
}
c.close();
* It is very important to close the cursor using the close()
method when you finish getting the data.
To get the number of elements contained in your cursor you can use the method getCount ()
Example:
Cursor cursor = db.obtenerSaldoClienteFavor(idClienteA);
Log.i("Datos cursor", "Número de elementos: " + cursor.getCount();
...
...