我正在尝试为我的Minecraft服务器编写一个商店插件,但每当有人执行/ purchase命令时我都会收到错误。
这是错误:
2012-07-03 04:27:28 [SEVERE] com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: ',3' 2012-07-03 04:27:28 [SEVERE] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3591) 2012-07-03 04:27:28 [SEVERE] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3525) 2012-07-03 04:27:28 [SEVERE] at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1986) 2012-07-03 04:27:28 [SEVERE] at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2140) 2012-07-03 04:27:28 [SEVERE] at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2620) 2012-07-03 04:27:28 [SEVERE] at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1662) 2012-07-03 04:27:28 [SEVERE] at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1581) 2012-07-03 04:27:28 [SEVERE] at com.Chipmunk9998.Cod.CodCommandExecutor.onCommand(CodCommandExecutor.java:1421) 2012-07-03 04:27:28 [SEVERE] at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40) 2012-07-03 04:27:28 [SEVERE] at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:166) 2012-07-03 04:27:28 [SEVERE] at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:479) 2012-07-03 04:27:28 [SEVERE] at com.Chipmunk9998.Cod.CodCommandExecutor.onCommand(CodCommandExecutor.java:1443) 2012-07-03 04:27:28 [SEVERE] at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40) 2012-07-03 04:27:28 [SEVERE] at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:166) 2012-07-03 04:27:28 [SEVERE] at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:479) 2012-07-03 04:27:28 [SEVERE] at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:821) 2012-07-03 04:27:28 [SEVERE] at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:781) 2012-07-03 04:27:28 [SEVERE] at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:764) 2012-07-03 04:27:28 [SEVERE] at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:34) 2012-07-03 04:27:28 [SEVERE] at net.minecraft.server.NetworkManager.b(NetworkManager.java:229) 2012-07-03 04:27:28 [SEVERE] at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:113) 2012-07-03 04:27:28 [SEVERE] at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:78) 2012-07-03 04:27:28 [SEVERE] at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:567) 2012-07-03 04:27:28 [SEVERE] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:459) 2012-07-03 04:27:28 [SEVERE] at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
这是我的代码:
if (cmdsender == null) {
File weaponFile = new File(plugin.getDataFolder(), "weapons.yml");
FileConfiguration weaponData = YamlConfiguration.loadConfiguration(weaponFile);
String sql = "UPDATE account_info SET Money = Money - "
+ weaponData.getString(args[0] + "." + args[1] + ".Price")
+ " WHERE Username = '" + args[2] + "'";
try {
plugin.st.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
}
sql = "UPDATE account_info SET Bought_" + args[0] + " = Bought_" + args[0]
+ " + ," + args[1] + " WHERE Username = '" + args[2] + "'";
try {
plugin.st.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
}
plugin.getServer().getPlayer(args[2]).sendMessage(
"You have successfully bought the "
+ weaponData.getString(args[0] + "." + args[1] + ".Name") + "."
);
return true;
}
我尝试使用谷歌搜索,但找不到任何有用的东西。
答案 0 :(得分:3)
看起来你在这一行中有错误:
sql = "UPDATE account_info SET Bought_" + args[0] + " = Bought_" + args[0]
+ " + ," + args[1] + " WHERE Username = '" + args[2] + "'";
args[1]
之前此字符串中有一个错误的逗号。如果args[0]
,args[1]
和args[2]
分别包含1
,3
和foo
,那么sql
将评估为:
UPDATE account_info SET Bought_1 = Bought_1 + ,3 WHERE Username = 'foo'
这显然是语法错误,并解释了您的错误消息Data truncation: Truncated incorrect DOUBLE value: ',3'
。
答案 1 :(得分:-2)
我在JSP中编码使用UPDATE查询更新数据库记录。 “UPDATE customer_details设置Customer_fname =?,Customer_lname =?,Customer_home_address =?,Customer_office_address =?,Customer_mobile_no =?,Customer_city =?,Customer_state = ?, Customer_dob =?where User_id =?
在最后一个User_id的参数....中,我不小心写了 ps.setString(9,uname)这是不同的数据类型的变量....这给我一个错误数据截断:错误的双值。
我用 ps.setInt(9,uid)更正了这是正确的变量和数据类型然后错误消失了.... !!