SQLException SQL语法中有错误

等离子

我是MySQL的新手,我正在尝试制作Discord机器人,该机器人可以保存Discord用户的ID和MySQL数据库的密钥。机器人启动时,它将加载MySQL并连接到数据库,然后尝试使用以下方法创建表(如果该表不存在):

try {
    PreparedStatement ps = this.connection.prepareStatement("create table if not exists keys (discord bigint(250), key bigint(250));");
    ps.execute();
} catch (SQLException ex) {
    ex.printStackTrace();
}

当我尝试运行该命令时,出现以下错误:

java.sql.SQLSyntaxErrorException: 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 'bigint(250))' at line 1
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:118)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
    at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:960)
    at com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:388)
    at main.java.bot.discord.utils.MySQL.update(MySQL.java:86)
    at main.java.bot.discord.utils.MySQL.init(MySQL.java:28)
    at main.java.bot.discord.utils.MySQL.<init>(MySQL.java:20)
    at main.java.bot.discord.Main.boot(Main.java:61)
    at main.java.bot.discord.Main.run(Main.java:56)
    at main.java.bot.discord.Main.main(Main.java:32)

要连接到数据库,我正在使用:

Class.forName("com.mysql.cj.jdbc.Driver");
this.connection = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database + "?useSSL=false serverTimezone=America/New_York", this.username, this.password);

我正在使用的MySQL驱动程序是mysql-connector v8.0.11就像我说的那样,我是MySQL的新手,所以我可能在做完全错误的事情。请让我知道我是否愿意。谢谢。

编辑:MySQL类中的第86行是我执行PreparedStatement的地方。

Elliott Fresh:

key保留字,请将列名更改为其他名称。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

值java.sql.SQLException:MONTH

从SQL Server存储过程的Java提高的SQLException?

值java.sql.SQLException:无效的列名

当我有单逗号和|时,SQL语法中有错误。

java.sql.SQLException:找不到数据

java.sql.SQLException:在“ on”附近:语法错误问题

您的SQL语法中有错误-休眠和mysql

java.sql.SQLException:连接已关闭

Java SQLException根据错误代码分开

您的SQL语法中有错误...在'float'/ CAST(rating_count AS float))附近是来自文档的average_rating'

SQLException:错误:“ \”处或附近的语法错误

您的SQL语法EXTRACT中有错误

如何修复代码中的SqlException错误语法错误?

错误的SQL语法引起的SQLException

致命错误:未捕获的PDOException:SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误

Hibernate java.sql.SQLException:无效的列名

线程“主”中的异常java.sql.SQLException:在“ s”附近:语法错误

未分类的SQLException for SQL

错误:第1行的SQL语法中有错误INSERT INTO

Rails-SQLite3 :: SQLException:在“ USING”附近:语法错误

java.sql.SQLException:连接已关闭

java.sql.SQLException:常规错误

记录java.sql.SQLException导致溢出

java.sql.SQLException: 参数数量错误错误

java.sql.SQLException:“.”附近:语法错误

MYSQL:您的 SQL 语法有错误

SqlException: 'nvarchar' 附近的语法不正确

您的 SQL 语法错误中有错误吗?

java.sql.SQLException:无限循环