2

我需要将大型 XML 数据存储到 CLOB 并将 CLOB 转换回 String

但问题是我们正在使用(Spring NamedParameterJdbc 模板)

SqlParameterSource paramSource = new BeanPropertySqlParameterSource(
            positionResponsesDO);
this.jdbcTemplate.update(sql, paramSource);

PositionResponsesDO 具有获取和设置属性的位置

private Clob xmlData;

现在我需要将字符串数据(大)转换为 Clob,将 Clob 转换为字符串。请向我建议最好的方法。

我不能使用文件操作,因为它是 WebApp

4

1 回答 1

3

您可以使用LobHandlerandLobCreator获取 Clob 和 Blob 并将它们变成其他东西。

Spring 文档在这里讨论了它们。

要将 clob 或 blob 列query()转换NamedParameterJdbcTemplateRowMapper.

LobHandler lobHandler = new DefaultLobHandler();
jdbcTemplate.query(sql, paramSource,
    new RowMapper<Void>() {
        public Void mapRow(ResultSet rs, int i) throws SQLException {
            String clobText = lobHandler.getClobAsString(rs, "clobColumnName");                                                
            byte[] blobBytes = lobHandler.getBlobAsBytes(rs, "blobColumnName");                                                
            return null;
        }
    });
于 2012-07-10T14:39:43.233 回答