- 已关闭**。此问题需要details or clarity。当前不接受答案。
- 想要改进此问题?**添加详细信息并通过editing this post阐明问题。
昨天关门了。
Improve this question
我正在使用java和sqlite
这是我的代码:
stmt = conn.prepareStatement("INSERT " +
(databaseType.equals("sqlite") ? "OR" : "") +
" IGNORE INTO channels (`name`, `command`, `perform`, `range`, `cooldown`, `tag`, `color`, `format`) VALUES " +
"('global', 'g', 'ALL', 0, 5, '&7[g]&f', '&7', '{channel} {group}{sender}» {color}{message}')," +
"('local', 'l', 'LOCAL', 30, 0, '&e[l]&f', '&e', '{channel} {group}{sender}» {color}{message}')," +
"('whisper', 'w', 'LOCAL', 3, 0, '&7[!]&f', '&8', '{channel} {group}{sender} &7susurrou pra você» {color}{message}')");
它生成以下查询
INSERT IGNORE INTO channels (`name`, `command`, `perform`, `range`, `cooldown`, `tag`, `color`, `format`) VALUES
('global', 'g', 'ALL', 0, 5, '&7[g]&f', '&7', '{channel} {group}{sender}» {color}{message}'),
('local', 'l', 'LOCAL', 30, 0, '&e[l]&f', '&e', '{channel} {group}{sender}» {color}{message}'),
('whisper', 'w', 'LOCAL', 3, 0, '&7[!]&f', '&8', '{channel} {group}{sender} &7susurrou pra você» {color}{message}')`
出现了这个错误
Error occurred while enabling Terminal v1.0-SNAPSHOT (Is it up to date?)
java.lang.RuntimeException: java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (near ",": syntax error)
at com.github.natanfoleto.terminal.database.repositories.ChannelRepository.createChannels(ChannelRepository.java:58) ~[?:?]
at com.github.natanfoleto.terminal.loaders.DatabaseLoader.run(DatabaseLoader.java:8) ~[?:?]
at com.github.natanfoleto.terminal.Terminal.runLoaders(Terminal.java:155) ~[?:?]
at com.github.natanfoleto.terminal.Terminal.onEnable(Terminal.java:62) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[patched_1.8.8.jar:git-PaperSpigot-445]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:332) [patched_1.8.8.jar:git-PaperSpigot-445]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:407) [patched_1.8.8.jar:git-PaperSpigot-445]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:359) [patched_1.8.8.jar:git-PaperSpigot-445]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:318) [patched_1.8.8.jar:git-PaperSpigot-445]
at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:408) [patched_1.8.8.jar:git-PaperSpigot-445]
at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:372) [patched_1.8.8.jar:git-PaperSpigot-445]
at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:327) [patched_1.8.8.jar:git-PaperSpigot-445]
at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:267) [patched_1.8.8.jar:git-PaperSpigot-445]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:563) [patched_1.8.8.jar:git-PaperSpigot-445]
at java.lang.Thread.run(Thread.java:834) [?:?]
Caused by: java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (near ",": syntax error)
at org.sqlite.DB.newSQLException(DB.java:383) ~[patched_1.8.8.jar:git-PaperSpigot-445]
at org.sqlite.DB.newSQLException(DB.java:387) ~[patched_1.8.8.jar:git-PaperSpigot-445]
at org.sqlite.DB.throwex(DB.java:374) ~[patched_1.8.8.jar:git-PaperSpigot-445]
at org.sqlite.NativeDB.prepare(Native Method) ~[patched_1.8.8.jar:git-PaperSpigot-445]
at org.sqlite.DB.prepare(DB.java:123) ~[patched_1.8.8.jar:git-PaperSpigot-445]
at org.sqlite.PrepStmt.<init>(PrepStmt.java:42) ~[patched_1.8.8.jar:git-PaperSpigot-445]
at org.sqlite.Conn.prepareStatement(Conn.java:404) ~[patched_1.8.8.jar:git-PaperSpigot-445]
at org.sqlite.Conn.prepareStatement(Conn.java:399) ~[patched_1.8.8.jar:git-PaperSpigot-445]
at org.sqlite.Conn.prepareStatement(Conn.java:383) ~[patched_1.8.8.jar:git-PaperSpigot-445]
at com.github.natanfoleto.terminal.database.repositories.ChannelRepository.createChannels(ChannelRepository.java:50) ~[?:?]
... 14 more
查询在sqlite studio上运行成功,但代码不起作用
我尝试手动编写查询,但不太奏效
1条答案
按热度按时间sr4lhrrt1#
我没有试过,但是在你的指令的最后有一个分号后面跟一个单引号'去掉单引号,这样它就说:
{color}{消息}')”);
实际上,你应该去掉所有的对角引号,我不知道它们是怎么叫的,但是你不需要它们,这样调试起来更容易。
如果前面的建议不起作用,请尝试删除此符号:»
此外,您还应该为该查询创建一个字符串变量,以便更轻松地记录和测试该查询: