我在尝试使用我的 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”列,则插入将成功。
提前致谢。