1

First of all I've looked up several topics on this but nothing specifically addressing this issue in Java.

I have the following method.

public String getCount() {
    SQLiteDatabase db = smokinDBOpenHelper.getWritableDatabase();
    String w = "Home";
    Cursor cursor = db.rawQuery("select * from " + smokinDBOpenHelper.INCIDENTS_TABLE + 
            " where " + KEY_LOCATION + " = 'Home'", null);

    int i = cursor.getCount();
    String s = ("You have " + i + " entries in this column");

    return s;
}

I would like this query to use the variable above it rather than a specific hard coded String "Home".

I've tried + {w} + {w%} + w and a few others, nothing seems to work

2 Answers 2

2

Try

Cursor cursor = db.rawQuery("select * from " + smokinDBOpenHelper.INCIDENTS_TABLE + 
        " where " + KEY_LOCATION + " = '" + w + "'", null);
Sign up to request clarification or add additional context in comments.

Comments

2

It's better to user the selectionArgs parameters that you set to null in your rawQuery method.

An example can be founde here rawQuery(query, selectionArgs)

1 Comment

For sure, otherwise its easy to attack my db. I just needed this part to work first. Now I'm on to that, thank you though

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.