xml - 将 Clob 与 Spring NamedParameterJdbc 模板结合使用

标签 xml string spring clob

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

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

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

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

private Clob xmlData;

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

我无法使用文件操作,因为它是 WebApp

最佳答案

您可以使用LobHandlerLobCreator将 Clob 和 Blob 变成其他东西。

Spring documentation在这里讨论它们。

要将 clob 或 blob 列转换为某些内容,您可以在 NamedParameterJdbcTemplate 上使用采用 RowMapperquery() 方法。

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

关于xml - 将 Clob 与 Spring NamedParameterJdbc 模板结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11415308/

相关文章:

ios - Web 服务如何工作?

java - 如果没有 Activity 事务,保存无效 - hibernate&spring

xml - 如何对名称中包含连字符的属性使用 groovy XMLbuilder

java - Spring MVC 页面 HTTP 状态 400 和不正确的 URL

java - CustomEditorConfigurer 的 customEditors 属性与 RangeArrayPropertyEditor、Spring 4.3.3 与 Spring Batch 3.0.7

spring - 从 Spring 的 @EventListener(condition = "...") 中的属性文件评估属性

Android工具栏主页按钮不显示

python - 如何在子字符串后捕获一定数量的字符?

c++ - 测试 C 字符串是否以后缀结尾的 C++ 函数

Java toTitleCase 函数