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
JdbcTemplate "queryForObject" and "query" is deprecated in Spring.
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.
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.
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));
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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With