I have an update query as below:
UPDATE SCHEMA_NAME.TABLE_NAME SET COLUMN_NAME = VALUE;
I am passing the below query as a String inside a prepared statement setter:
UPDATE ?.? SET ? = ?
And inside my prepared statement setter java class, I am setting the values as below:
ps.setString(1, "mySchema");
ps.setString(2, "myTable");
ps.setString(3, "myColumn");
ps.setString(4, "myValue");
However, on running the java program which prepares above query and runs it I am getting below error:
DB2 SQL error: SQLCODE: -104, SQLSTATE: 42601
How can I dynamically create the query in the way I have described above ?
You can’t use parameterization (i.e.
?) to set the schema or table name. Instead, you just need to insert the correct table into the string in Java before you prepare the statement.