我是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的地方。
key
是保留字,请将列名更改为其他名称。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句