Spring JdbcTemplate获取字节数组

6
我将XML作为字节数组存储在Oracle数据库的CLOB列中。现在尝试在Spring批处理中使用JdbcTemplate将结果集作为字节数组获取,但是会抛出以下异常:
org.springframework.dao.InvalidDataAccessApiUsageException:StatementCallback; SQL [select DEFAULT_REPORT_PARAM_XML from cfg_report_list where report_name='Payments STP Report']; Unsupported feature; nested exception is java.sql.SQLFeatureNotSupportedException: Unsupported feature 下面是我正在使用的代码示例:
byte[] configxml = jdbcTemplate.queryForObject(
                "select DEFAULT_REPORT_PARAM_XML from cfg_report_list  where report_name='Payments STP Report'", 
                byte[].class);

请注意,我正在使用spring-batch 3.0.1 RELEASE版本。
请告诉我如何解决这个问题。
谢谢。
3个回答

4

不需要调用getBlob()方法; 你可以简化它,就像这样:

byte[] configxml = jdbcTemplate.queryForObject(
    "select DEFAULT_REPORT_PARAM_XML from cfg_report_list  where report_name='Payments STP Report'",
    (rs, rowNum) -> rs.getBytes(1));

3
尝试使用RowMapper,然后使用ResultSet.getBlob
public class YourXmlRowMapper implements RowMapper<byte[]> {

    public byte[] mapRow(ResultSet rs, int rowNum) throws SQLException {
         Blob column = rs.getBlob("DEFAULT_REPORT_PARAM_XML");
         return column.getBytes(1, column.length());
    }
}



byte[] configxml = jdbcTemplate.queryForObject(
            "select DEFAULT_REPORT_PARAM_XML from cfg_report_list  where  report_name='Payments STP Report'", 
           new YourXmlRowMapper());

0

使用byte[]而不是Byte[]。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接