0
我有在做同样的事情,但在不同的表几预处理语句:准备语句设置表NEM用于插入
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,表名))
但我m如果这个错误:
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
有没有办法做到这一点?
好的,谢谢,我会再次重新考虑我的模式 – 2013-04-27 19:55:09