Spring jdbctemplate get byte array

I store xml as a byte array in clob column in oracle database. Now trying to use jdbctemplate to get the result set as a byte array in spring batch.It throwing an Exception below

org.springframework.dao.InvalidDataAccessApiUsageException : StatementCallback; SQL [select DEFAULT_REPORT_PARAM_XML from cfg_report_list, where report_name = 'STP Transaction Report' "]; Unsupported function; nested exception java.sql.SQLFeatureNotSupportedException: Unsupported function

Sample PFB Code I Use

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

Please note that I am using spring -batch 3.0.1 RELEASE.

Please let me know the solution to this problem.

thanks

+4
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());
+3

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));
+2

Just use byte [] instead of Byte [].

0
source

Source: https://habr.com/ru/post/1619169/


All Articles