1

I want to use variable value in where condition in select query.

But database reconnized it as a String.

What should i do?

Here is code

public static void getCommentListOnlyTwoFromDB(int id) {
       
        String sql = "SELECT writer, contents, rating, time, recommend FROM CommentList WHERE movieID=id"; // HERE
        ArrayList<CommentModel> data = new ArrayList<>();
        Cursor cursor = database.rawQuery(sql, null );
    }

When I execute this code. 'WHERE movieID=id' is just String as movieID=id...

I want to put id value in movieID.

please help me.

THANK YOU!

1 Answer 1

2
public static void getCommentListOnlyTwoFromDB(int id) {
       
        String sql = "SELECT writer, contents, rating, time, recommend FROM CommentList WHERE movieID=" + id; // HERE
        ArrayList<CommentModel> data = new ArrayList<>();
        Cursor cursor = database.rawQuery(sql, null );
    }
Sign up to request clarification or add additional context in comments.

1 Comment

OMG..... I'm so so EMBARRASSED. I tried various things. But i don't tried to "movieID=" + id...i tried to "movieID" + "=id".. i'm stupid.. i'm sorry.. and THX

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.