gpt4 book ai didi

java - 实体表错误 13037 : Illegal DOUBLE PREC constant

转载 作者:行者123 更新时间:2023-11-30 07:59:37 24 4
gpt4 key购买 nike

尝试使用 Java JDBC 代码将记录添加到 SolidDB 时,出现以下错误。

下面是抛出异常的方法:

    public void addData(User data) {
Connection conn = null;
try {
conn = dataSource.getConnection();
if (conn == null || conn.isClosed()) {
throw new RuntimeException("Could not open connection");
}
String query="INSERT INTO USER "
+ "(ID, NAME, PASSWORD, ENABLED, REQUIRE_RESET)"
+ "VALUES (?, ?, ?, ?, ?);";

PreparedStatement ps = conn.prepareStatement(query);
// "ID" column is INTEGER, and partition field in UserData is int.
ps.setString(1, data.getId());
ps.setString(2, data.getName());
ps.setString(3, data.getPassword());
// "ENABLED" column is INTEGER, and enabled field in UserData is boolean.
ps.setInt(4, data.isEnabled()? 1:0);
ps.setString(5, data.isRequireReset()?"Y":"N");
if (ps.executeUpdate() < 1) {
throw new RuntimeException("Could not save User, executeUpdate() returned a value < 1");
}

} Catch (SQLException e) {
throw new DataLayerException("Could not save the User Data.", e);
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
}
}
}
}

我尝试过直接硬编码这些值,但仍然失败。如果我从插入语句中删除“ID”和“ENABLED”列,插入就会成功。

提前致谢。

最佳答案

PreparedStatement 索引为 1-based (另见setXX javadoc)。因为您使用 0,并且驱动程序不会警告您,所以所有内容都被“转移”,从而导致了问题。

修复:

ps.setString(1, data.getId());
ps.setString(2, data.getName());
ps.setString(3, data.getPassword());
ps.setInt(4, data.isEnabled()? 1:0);
ps.setString(5, data.isRequireReset()?"Y":"N");

关于java - 实体表错误 13037 : Illegal DOUBLE PREC constant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32141582/

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