Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring jdbctemplate get byte array

I am storing xml as byte array in the clob column in the oracle database. Now trying to use jdbctemplate to get the resultset as byte array in spring batch.It's throwing below Exception

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

PFB code sample which I am using

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.

Kindly let me know solution to this problem.

Thanks

like image 435
murali Avatar asked Dec 09 '15 08:12

murali


People also ask

Is JdbcTemplate deprecated?

JdbcTemplate "queryForObject" and "query" is deprecated in Spring.

What is difference between Namedjdbctemplate and JdbcTemplate?

Functionally, there's no difference between Spring's JdbcTemplate and it's variant, NamedParameterJdbcTemplate except for : NamedParameterJdbcTemplate provides a better approach for assigning sql dynamic parameters instead of using multiple '?' in the statement.

What is the use of NamedParameterJdbcTemplate?

NamedParameterJdbcTemplate class is a template class with a basic set of JDBC operations, allowing the use of named parameters rather than traditional '?' placeholders. This class delegates to a wrapped JdbcTemplate once the substitution from named parameters to JDBC style '?' placeholders is done at execution time.


2 Answers

No need to call getBlob(); you should be able to simplify like it like so:

byte[] configxml = jdbcTemplate.queryForObject(
    "select DEFAULT_REPORT_PARAM_XML from cfg_report_list  where report_name='Payments STP Report'",
    (rs, rowNum) -> rs.getBytes(1));
like image 106
Dave L. Avatar answered Sep 19 '22 12:09

Dave L.


Try to use a RowMapper and then use 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());
like image 45
Ralph Avatar answered Sep 20 '22 12:09

Ralph