Luke
Luke

Reputation: 527

Android sqlite - How to manage a Integer value in where clause

I've a problem with the query to mananage the sqlite database in android.

this is a sample method :

public Cursor selectID( Integer id){
// query code for select
}

But all the query method that i see , not allow me to manage an integer parameter, or anything else except a String parameter. Usually i use the rawQuery method:

for example :

db.rawQuery("Select id from dbName where id = ?", new String[] {id});

But that, as i said , is not possible with Integer or other parameter ( for example

new Integer[] {id};

How i can do to solve my problem?

Upvotes: 4

Views: 7318

Answers (1)

Ken Wolf
Ken Wolf

Reputation: 23269

Use String.valueOf(id) which will return the String representation of your int.

http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#valueOf(int)

So your statement will look like:

db.rawQuery("Select id from dbName where id = ?", new String[] {String.valueOf(id)});

Upvotes: 7

Related Questions