Home >Database >Mysql Tutorial >Why Can't I Use Prepared Statements for Table Names in My SQL Query?
In an attempt to use prepared statements to set a table name for data selection, an error persists during query execution. The provided sample code exhibits the issue:
[Microsoft][ODBC Microsoft Access Driver] Parameter 'Pa_RaM000' specified where a table name is required. ... private String query1 = "SELECT plantID, edrman, plant, vaxnode FROM [?]"; //?=date
The culprit in this scenario is the inability to substitute a table name with a parameter. Prepared statements are not suitable for this purpose; the table name must be hardcoded into the query. To resolve the issue, consider the following approach:
private String query1 = "SELECT plantID, edrman, plant, vaxnode FROM [" + reportDate + "?]";
The above is the detailed content of Why Can't I Use Prepared Statements for Table Names in My SQL Query?. For more information, please follow other related articles on the PHP Chinese website!