java com.mysql.jdbc.MysqlDataTruncation: 数据截断: 截断不正确 DOUBLE 值: ',3'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11303248/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 04:35:59  来源:igfitidea点击:

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: ',3'

javamysqljdbctruncation

提问by David Carpenter

I'm trying to write a shop plugin for my Minecraft server, but I keep getting an error whenever anyone does the /purchase command.

我正在尝试为我的 Minecraft 服务器编写一个商店插件,但是每当有人执行 /purchase 命令时我都会收到错误消息。

Here's the error:

这是错误:

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)

And here's my code:

这是我的代码:

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;
}

I tried googling it, but couldn't find anything that helped.

我试着用谷歌搜索它,但找不到任何有帮助的东西。

回答by eggyal

It looks like you have an error in this line:

看起来您在这一行中有错误:

  sql = "UPDATE account_info SET Bought_" + args[0] + " = Bought_" + args[0]
    + " + ," + args[1] + " WHERE Username = '" + args[2] + "'";

There is an erroneous comma in this string before args[1]. If args[0], args[1]and args[2]contain 1, 3and foorespectively, then sqlwill evaluate to:

在这个字符串之前有一个错误的逗号args[1]。如果args[0]args[1]args[2]包含13foo分别,那么sql将评估为:

UPDATE account_info SET Bought_1 = Bought_1 + ,3 WHERE Username = 'foo'

Which is clearly a syntax error and explains your error message Data truncation: Truncated incorrect DOUBLE value: ',3'.

这显然是一个语法错误并解释了您的错误消息Data truncation: Truncated incorrect DOUBLE value: ',3'

回答by prashant shastri

I was coding in JSP for updating database records using UPDATE query. "UPDATE customer_details set Customer_fname=?,Customer_lname=?,Customer_home_address=?,Customer_office_address=?,Customer_mobile_no=?,Customer_city=?,Customer_state=?,Customer_dob=? where User_id=?

我在 JSP 中编码以使用 UPDATE 查询更新数据库记录。"UPDATE customer_details set Customer_fname=?,Customer_lname=?,Customer_home_address=?,Customer_office_address=?,Customer_mobile_no=?,Customer_city=?,Customer_state=?,Customer_dob=? where User_id=?

in last User_id's parameter...., I accidentally write ps.setString(9,uname)which was different variable with different datatype....which give me an error of data truncation:incorrect doublevalue.

在最后一个 User_id 的参数中......,我不小心写了ps.setString(9,uname)这是不同数据类型的不同变量......这给了我一个数据截断错误:不正确的 doublevalue

i corrected it with ps.setInt(9,uid)which was correct variable and datatype then error was gone....!!

我用ps.setInt(9,uid)更正了它,这是正确的变量和数据类型,然后错误消失了......!