Categories
android sqlite

Android parameterized sql query not working

If I hardcode a number into the where section I get the rows I’m expecting back

Cursor cursor = db.query( tableName, 
new String[] {colID, colString, colNumber },
colNumber + "=14",
null,
null, null, null, null);

If I instead put the number in as a parameter, I don’t get any rows back.

Cursor cursor = db.query( tableName, 
new String[] {colID, colString, colNumber },
colNumber + "=?",
new String[] { String.valueOf(14) },
null, null, null, null);

What am I doing wrong in the second case?

Create table statements:

db.execSQL("CREATE TABLE "
+ otherTableName + " ("
+ otherTableID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ otherTableString + " TEXT"
+ ");");
db.execSQL("CREATE TABLE "
+ tableName + " ("
+ colID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ colString + " TEXT, "
+ colNumber + " REFERENCES "
+ otherTableName + "(" + otherTableID
+ "));");