我需要将大型 XML 数据存储到 CLOB 并将 CLOB 转换回字符串
但问题是我们正在使用(Spring NamedParameterJdbc模板)
SqlParameterSource paramSource = new BeanPropertySqlParameterSource(
positionResponsesDO);
this.jdbcTemplate.update(sql, paramSource);
PositionResponsesDO 具有获取和设置属性的位置
private Clob xmlData;
现在我需要将字符串数据(大)转换为 Clob,并将 Clob 转换为字符串。 请向我建议最好的方法。
我无法使用文件操作,因为它是 WebApp
最佳答案
您可以使用LobHandler
和 LobCreator
将 Clob 和 Blob 变成其他东西。
Spring documentation在这里讨论它们。
要将 clob 或 blob 列转换为某些内容,您可以在 NamedParameterJdbcTemplate
上使用采用 RowMapper
的 query()
方法。
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/