0

I got a null value when data is present at the location in sqlite

Cursor c = db.query("SELECT * FROM table WHERE id " = '" + value + "'", null);

if(c !=null && c.moveToFirst())
{
     temp = c.getString(c.getColumnIndex(b1));

     Log.v(TAG, ""+temp);
}

The log file is

------------
Tag   Text
-------------
class null 

------------- 

The value is present but i get null can it be sorted out.

if cursor is null it obviously should skip the if statement but it executes the statement.

For some other values i get the answer

Tag    Text
-----------
class  100
----------
class  86

Thank you for the time and response given

1 Answers1

0

You didn't write the right SQLquery
this is the right query

Cursor c = db.rawQuery("SELECT * FROM "+ table +" WHERE id  = " + value , null);

you also can use db.query() method like that

    Cursor cursor = db.query(TABLE_NAME, // a. table
            COLUMNS, // b. column names as array of strings

            KEY_ID + "= ?", // c. selections

            new String[] { String.valueOf(id) }, // d. selections args
            null, // e. group by
            null, // f. having
            null, // g. order by
            null); // h. limit

    // 3. if we got results get the first one
    if (cursor != null)
        cursor.moveToFirst();

    temp = cursor.getString(c.getColumnIndex(b1));
Ahd Radwan
  • 1,090
  • 4
  • 14
  • 31
  • The query is rightly written and he says it is working! – Rachit Mishra Jan 15 '15 at 07:04
  • Thank you to all for response, using the same query i got other results in log file as mentioned in question. However i tried another style of query as String sql =" "; String =......; SqliteDatabase db = -----; Cursor c = db.query(...); then that worked fine – Aaron Waghmare Jan 20 '15 at 09:13