本文介绍了传递给Spring JDBC LobHandler之后关闭Java InputStream吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以这种代码传递给Spring JDBC lobCreator.setBlobAsBinaryStream(,,)之后,是否需要在Java中手动关闭InputStream(bean.getContentAsStream())?
Does it need manually close InputStream (bean.getContentAsStream()) in java after pass to Spring JDBC lobCreator.setBlobAsBinaryStream(,,) in such code?
getJdbcTemplate().execute(
"INSERT INTO file (" +
"id, " + //1
"FILE_DATA) " + //2
" VALUES (?, ?)",
// lobhandler is instance of org.springframework.jdbc.support.lob.OracleLobHandler
new AbstractLobCreatingPreparedStatementCallback(lobhandler){
@Override
protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException, DataAccessException {
ps.setString(1, bean.getRecordId());
lobCreator.setBlobAsBinaryStream(ps, 2, bean.getContentAsStream(), (int) bean.getContentSize());
}
});
推荐答案
我希望spring将其关闭,但文档未说明.您可以通过创建一个InputStream包装器轻松地进行测试,该包装器记录一条消息或在关闭该消息时引发异常.
I expect spring will close it but the doc does not say. You can easily test by creating an InputStream wrapper that logs a message or throws an exception when it is closed.
这篇关于传递给Spring JDBC LobHandler之后关闭Java InputStream吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!