Janjan
Janjan

Reputation: 51

search data in SQLite

Can someone help me and tell me what's wrong here?

String date = "Samstag, 30.7.2011";
        myDB = this.openOrCreateDatabase(MY_DB_NAME, MODE_PRIVATE, null);     
        String load = "SELECT db_scheine FROM ZahlenUndDatum where db_datum= "+date+"";

       Cursor c = myDB.rawQuery(load, null);
       String test = c.toString();
       Log.d("output", test);

I would like to search for the date in the database and then return the value of the record from db_scheine.

Upvotes: 1

Views: 613

Answers (1)

JustDanyul
JustDanyul

Reputation: 14044

try adding moveToFirst()

Cursor c = myDB.rawQuery(load, null);
c.moveToFirst();
String test = c.toString();

The rawQuery() method, will create a cursor, which is initially placed before the first row. So you can do something like this:

Cursor c = myDB.rawQuery(load, null);
while(c.moveToNext()) {
// do stuff
}

Without skipping the first row :)

UPDATE: Your date is giving problems as well, im guessing the db_datum field is a string, enclose the string in quotes like so:

String load = "SELECT db_scheine FROM ZahlenUndDatum WHERE db_datum= '"+date+"'";

Upvotes: 2

Related Questions