Using Prepared Statements to set Table Name

后端 未结 7 1916
生来不讨喜
生来不讨喜 2020-11-22 11:57

I\'m trying to use prepared statements to set a table name to select data from, but I keep getting an error when I execute the query.

The error and sample code is di

7条回答
  •  天涯浪人
    2020-11-22 12:24

    As a number of people have said, you can't use a statement parameter for a table name, only for variables as part of the condition.

    Based on the fact you have a variable table name with (at least) two table names, perhaps it would be best to create a method which takes the entity you are storing and returns a prepared statement.

    PreparedStatement p = createStatement(table);
    

提交回复
热议问题