user2629955
user2629955

Reputation:

Android sqlite Where clause returning one row column with id

I want to get a single column of a row with an id , shall I do

 String selQ = "SELECT " + name + " FROM " + table+ " WHERE " + id+ " = '" + id + "'";

or

 String selQ = "SELECT * FROM " + table + " WHERE " + id+ " = '" + id + "'";

Shall I get a cursor?

Upvotes: 0

Views: 2819

Answers (2)

Yohannes Ejigu Ademe
Yohannes Ejigu Ademe

Reputation: 84

you can use query() method

private Cursor getSingleRow(int id){    
    Cursor cur = db.query(TABLE, null,
                 "_id= ?", new String[] { "" + id }, null,
                null, null);
        if (cur != null) {
            cur.moveToFirst();
        }
        return cur;
}

or you can execute row query just like what you have proposed with some errors removed

db.rawQuery("SELECT * from " + TABLE_NAME
            + "WHERE _id="+id , null);

Upvotes: 1

Joshua Byer
Joshua Byer

Reputation: 519

* means all the columns in the table, if you only want the name you need to specify. You can use the rawQuery() function once you made your string.

Upvotes: 0

Related Questions