Java + MySQL用于我的游戏服务器项目。我还是有问题-
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 '(connection) (`uuid`, `name`, `join_date`, `group`) VALUES (5dcd14f9 at line 1
uuid应该是5dcd14f9 -....-.....-...点是应该在那里存在的字符,而破折号只是破折号。由于某种原因,我遇到了一个问题,即它仅获得uuid的第一部分。我是否缺少某些内容,或者我的语法确实存在问题?那是我的代码,基本上就是错误:
PreparedStatement addPlayer = mySQL.getConnection().prepareStatement("INSERT INTO " + mySQL.getConnection() + " (uuid, name, join_date, group) VALUES (?,?,?,?)");
我当然将uuid强制转换为字符串,并将其作为值添加到第一列。我查看了其他解决方案并尝试了它们,但它们似乎没有用。
mySQL.getConnection().toString()
产生了"(connection)"
,这不是要插入的表名的有效语法。 也许代替:
PreparedStatement addPlayer = mySQL.getConnection().prepareStatement("INSERT INTO " + mySQL.getConnection() + " (uuid, name, join_date, group) VALUES (?,?,?,?)");
您想写类似的东西:
PreparedStatement addPlayer = mySQL.getConnection().prepareStatement("INSERT INTO " + getTableName() + " (uuid, name, join_date, group) VALUES (?,?,?,?)");
从您的错误中可以看到,mySQL.getConnection().toString()
产生了"(connection)"
,这不是要插入的表名的有效语法。
也许代替:
PreparedStatement addPlayer = mySQL.getConnection().prepareStatement("INSERT INTO " + mySQL.getConnection() + " (uuid, name, join_date, group) VALUES (?,?,?,?)");
您想写类似的东西:
PreparedStatement addPlayer = mySQL.getConnection().prepareStatement("INSERT INTO " + getTableName() + " (uuid, name, join_date, group) VALUES (?,?,?,?)");