Mariadb/MySQL JAVA准备语句语法错误
我真的不明白我做错了什么来得到这个错误 printline的输出是Mariadb/MySQL JAVA准备语句语法错误,mysql,sql,mariadb,Mysql,Sql,Mariadb,我真的不明白我做错了什么来得到这个错误 printline的输出是 // Attempt to get 1 transaction String sqlQuery = "INSERT INTO '" + this.crawlPageTableName + "' (url, status) VALUES (?, 'added')";
// Attempt to get 1 transaction
String sqlQuery = "INSERT INTO '" + this.crawlPageTableName
+ "' (url, status) VALUES (?, 'added')";
PreparedStatement prest = connect.prepareStatement(sqlQuery);
prest.setString(1, this.url);
System.out.println("Querying with: " + sqlQuery);
// Result set get the result of the SQL query
this.resultSet = prest.executeQuery();
我在这里真的很迷茫,因为来自打印行的同一查询通过phpMyAdmin直接在MariaDB服务器上工作。我认为不应该用任何单引号括住表名:
Querying with: INSERT INTO 'crawlPage' (url, status) VALUES (?, 'added')
java.sql.SQLSyntaxErrorException: (conn=1877278) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''crawlPage' (url, status) VALUES ('
我认为您不应该在表名中使用任何单引号:
Querying with: INSERT INTO 'crawlPage' (url, status) VALUES (?, 'added')
java.sql.SQLSyntaxErrorException: (conn=1877278) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''crawlPage' (url, status) VALUES ('
如果表名需要转义,它们应该用反勾号括起来,而不是单引号。如果表名需要转义,它们应该用反勾号括起来,而不是单引号。