vendredi 10 avril 2015

SQLiteException: near "u": syntax error (code 1)

I'm getting an error on my rawQuery which I am trying to join two tables?



SELECT Calories FROM CalorieIntake_Table c INNER JOIN Users_Table u ON c.USER_ID = u.U_IDWHERE u.U_ID =?


Here is the code for the Query:



public CalorieIntake getuserIntake(int id) {
CalorieIntake calorieIntake = null;
SQLiteDatabase db = getReadableDatabase();
final String UserintQuery = "SELECT " + KEY_CALORIES + " FROM "
+ TABLE_CALORIE_INTAKE + " c " + " INNER JOIN " + TABLE_USERS + " u " +
"ON" + " c." + KEY_USER_ID + " = u." + KEY_U_ID + "WHERE u." + KEY_U_ID + " =?";
Cursor cursor = db.rawQuery(UserintQuery, new String[]{String.valueOf(id)});

if (cursor != null && cursor.getCount() > 0) {
cursor.moveToFirst();
calorieIntake = new CalorieIntake(cursor.getInt(0), cursor.getString(1), cursor.getDouble(2));


}

return calorieIntake;
}

Aucun commentaire:

Enregistrer un commentaire