gpt4 book ai didi

java - 错误: No operations allowed after statement closed

转载 作者:行者123 更新时间:2023-12-02 00:57:45 28 4
gpt4 key购买 nike

我正在尝试执行此代码,但出现此错误,我知道我必须使用

关闭连接
preparedStatement.close() 

但是在治疗完成之前它就关闭了,并且给了我以下错误

Caused by: java.sql.SQLException: No operations allowed after statement closed.

我的代码

    private void fakesAssociate(List<Map<String, Object>> Employees) {
coreEmployees.forEach(row -> {
try {
myrefJdbcTemplate.update("INSERT INTO `n_associate` (`active`, `first_name`, `birthday`) VALUES ( ?, ?, ? );", preparedStatement -> {
preparedStatement.setBoolean(1, true);
preparedStatement.setString(2, String.valueOf(row.get("usual_first_name")));

Date birthdate = ((Date) row.get("birth_date"));
if (birthdate != null) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(birthdate);
calendar.set(Calendar.YEAR, 1970);
preparedStatement.setDate(3, new Date(calendar.getTime().getTime()));
} else {
preparedStatement.setDate(3, null);
}

preparedStatement.close();
});

});
} catch (DataIntegrityViolationException e) {
String queryAssociate = "UPDATE n_associate SET `active`= ? " +
WHERE n_associate.first_name = ?;";

myrefJdbcTemplate.update(queryAssociate, preparedStatement -> {

preparedStatement.setBoolean(1, false);
preparedStatement.close();

});
}
});
}

请帮忙看看如何解决

最佳答案

不要关闭语句。 JdbcTemplate 需要打开它才能执行它。 JdbcTemplate 将在使用完毕后关闭该语句。

关于java - 错误: No operations allowed after statement closed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61119507/

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