问题
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());
}
});
回答1:
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.
来源:https://stackoverflow.com/questions/10946849/close-java-inputstream-after-pass-to-spring-jdbc-lobhandler