gpt4 book ai didi

JAVA mysql 插入错误

转载 作者:可可西里 更新时间:2023-11-01 08:28:39 25 4
gpt4 key购买 nike

 private final static String INSERT = "INSERT INTO electric_usage" +
"(objId, useTime, name, usage) " +
"VALUES (?, ?, ?, ?)";

public static boolean insertUsage(int index, Timestamp time, String name, double usage) {
Connection con = null;

try {
con = DBManager.getInstance().getConnection();

PreparedStatement stmt = con.prepareStatement(INSERT);

java.util.Date today = new java.util.Date();


stmt.setInt(1, index);
stmt.setTimestamp(2, time);
stmt.setString(3, name);
stmt.setDouble(4, usage);
stmt.addBatch();

stmt.executeBatch();
stmt.close();

} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
DBManager.getInstance().close();
}

return true;


}

像这样进行 INSERT 查询但是这段代码出现语法错误

其他加载查询工作正常,只有这个 INSERT 查询发生错误

我正在尝试在控制台中插入查询,但出现同样的错误

我的查询有误吗?

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 'usage) VALUES (192, '2015-09-10 13:55:57', 'test', 0.0045196452704869055)' at line 1

表格是

objId(int length 8 not null)
useTime(timestamp length 0 not null)
name (varchar length 255 not null)
usage (double length 11 not null)

最佳答案

index 是保留字,因此您不应使用它来命名列。此处保留字列表:http://dev.mysql.com/doc/refman/5.6/en/keywords.html

关于JAVA mysql 插入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32493338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com