【问题标题】:Close Java InputStream after pass to Spring JDBC LobHandler?传递给 Spring JDBC LobHandler 后关闭 Java InputStream?
【发布时间】:2012-06-12 09:28:58
【问题描述】:

在这样的代码中传递给Spring JDBC lobCreator.setBlobAsBinaryStream(,,)后是否需要在java中手动关闭InputStream(bean.getContentAsStream())?

 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());
                    }
                });

【问题讨论】:

    标签: java spring jdbc blob inputstream


    【解决方案1】:

    我希望春天会关闭它,但文档没有说。您可以通过创建一个记录消息或在关闭时引发异常的 InputStream 包装器来轻松进行测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-03
      • 1970-01-01
      • 2012-08-22
      • 2018-05-02
      • 1970-01-01
      • 2019-02-01
      • 1970-01-01
      相关资源
      最近更新 更多