Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 690
Luke Avatar asked Mar 16 '23 23:03

Luke


1 Answers

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)});
like image 119
Ken Wolf Avatar answered Apr 06 '23 05:04

Ken Wolf