Close Java InputStream after pass to Spring JDBC LobHandler?

为君一笑 提交于 2019-12-13 07:09:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!