Home >Java >javaTutorial >How Can I Use a Parameterized Table Name in a SQL Query?
When attempting to utilize prepared statements to define a table name for data retrieval, users often encounter errors. This issue arises when a parameter is used in place of a required table name.
Consider the following example:
private String query1 = "SELECT plantID, edrman, plant, vaxnode FROM [?]"; // ?=date
This query attempts to use a parameter (?) to represent the table name, which is not supported. Instead, the table name must be hard-coded.
To resolve this issue, declare the table name explicitly in the query:
private String query1 = "SELECT plantID, edrman, plant, vaxnode FROM [" + reportDate + "]?"";
This modification ensures that the table name is properly specified, enabling successful execution of the query.
The above is the detailed content of How Can I Use a Parameterized Table Name in a SQL Query?. For more information, please follow other related articles on the PHP Chinese website!