我有一些 Prepared 语句在不同的表上做同样的事情:
ReportImageWrongLang = con.prepareStatement("INSERT INTO userReportedWrongLang VALUES (?,?,?) ON DUPLICATE KEY UPDATE UserId=UserID");
ReportImageProhibited = con.prepareStatement("INSERT INTO userReportedImages VALUES (?,?,?) ON DUPLICATE KEY UPDATE UserId=UserID");
ReportElse = con.prepareStatement("INSERT INTO Reportelse VALUES (?,?,?) ON DUPLICATE KEY UPDATE UserId=UserID");
我根据我的 java 程序上的某个事件调用此语句。
我想将这 3 个语句更改为一个语句:
Report = con.prepareStatement("INSERT INTO ? VALUES (?,?,?) ON DUPLICATE KEY UPDATE UserId=UserID");
并将第一个参数设置为表名 (Report.setString (1,tableName))
但我收到此错误:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''userreportedimages' VALUES ('3',331,1) ON DUPLICATE KEY UPDATE UserId=UserID' at line 1
有什么办法吗?