【发布时间】:2013-04-27 18:39:19
【问题描述】:
我有一些准备好的语句在不同的表上做同样的事情:
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
有什么办法吗?
【问题讨论】: