0

I'm trying to make a query with a PreparedStatement like this:

UPDATE PLAYER SET ? = ? WHERE ID = ? 

but I get

Error: java.sql.SQLSyntaxErrorException: ORA-01747

When I use code like this:

UPDATE PLAYER SET NAME = ? WHERE ID = ? 

It works. However, I want to use 3 arguments in my method. Is that possible?

4
  • 1
    I don't think you can replace objects with parameters. Commented Sep 12, 2016 at 13:33
  • Test with upper code is working but with errors. Commented Sep 12, 2016 at 13:35
  • 1
    Why not just include logic in your Java code to determine which column to update? Or, better yet, craft the logic of your query to handle this. Commented Sep 12, 2016 at 13:36
  • 1
    Possible duplicate of PreparedStatement: Can I use the column name as parameter? Commented Sep 12, 2016 at 14:36

1 Answer 1

0

This is not supported by PreparedStatement by itself

you can use string.replace but thats exactly what you should avoid when using preparedStatement (for sql injections)

if you are using Hibernate you can jump to Criteria and this would be very easy to do

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.