0

In my current project, I have a function with argument (e.g., int badgID in the following code snippet). This function connects with Apache Derby database, creates table (e.g., FIRSTTABLE), then query to FIRSTTABLE table. The query statement uses function argument for query (e.g., ID = $badgeID ). My question: Is ID = $badgeID the right way from a syntax point of view?. I have tried this case, but it is not working.

public void getprofile (int badgeID) {

// Create connection with Apache-Derby Database.   

// Create table in Apache Derby datbase.
String createString = " CREATE TABLE FIRSTTABLE "
                    + "(ID INT PRIMARY KEY, "
            + "PREF INT, "
                    + " NAME VARCHAR(12))";


//  SQL query on table
querystmt = "SELECT * FROM FIRSTTABLE WHERE  ID = $badgeID"

}

1 Answer 1

3

that's php syntax...

in java you would write

String querystmt = "SELECT * FROM FIRSTTABLE WHERE  ID = " + badgeID;
Sign up to request clarification or add additional context in comments.

1 Comment

Simple string concatenation like this often works fine. For more complex scenarios, you'll want to use a prepared statement, and use placeholders, and use the JDBC API to supply placeholder values at execution time. But for now, start with string concatentation to become comfortable with how the queries work.

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.