问题描述
以下ItemReader bean通过PrestDriver读取行。执行批处理时,出现以下错误消息:
org.springframework.batch.core.step.skip.NonSkippableReadException: Non-skippable exception during read
at org.springframework.batch.core.step.item.FaultTolerantChunkProvider.read(FaultTolerantChunkProvider.java:105) ~[spring-batch-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:126) ~[spring-batch-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
.....
Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: Attempt to process next row
Failed; sql [SELECT * FROM ......]; getRow; nested exception is
java.sql.sqlFeatureNotSupportedException: getRow
ItemReader代码
@Bean
public ItemReader<ExportDto> itemReader() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.facebook.presto.jdbc.PrestoDriver");
dataSource.setUrl("jdbc:presto: ");
dataSource.setUsername("....");
dataSource.setPassword("....");
JdbcCursorItemReader<ExportDto> reader = new JdbcCursorItemReader<ExportDto>();
reader.setDataSource(dataSource);
reader.setsql("SELECT * FROM .....'");
BeanPropertyRowMapper<ExportDto> rowMapper = new BeanPropertyRowMapper<>(ExportDto.class);
reader.setRowMapper(rowMapper);
return reader;
}
我已经创建了一个“ hello world”应用程序来测试驱动程序,这次使用普通的JDBCDriver。该测试成功。
String url = "jdbc:presto:.....";
Properties properties = new Properties();
properties.setProperty("user","....");
properties.setProperty("password","....");
properties.setProperty("SSL","true");
try {
Connection conn = DriverManager.getConnection(url,properties);
if (conn == null) {
System.out.print("NULL");
} else {
Statement stmt = conn.createStatement();
String sql = "SELECT distinct .....";
ResultSet rs = stmt.executeQuery(sql);
// Extract data from result set
while (rs.next()) {
// Retrieve by column name
String programs = rs.getString("prg");
}
// Clean-up environment
rs.close();
stmt.close();
conn.close();
}
为什么会发生这种情况?或一些解决方法将不胜感激。
谢谢
解决方法
默认情况下,JdbcCursorItemReader
验证光标在每个已处理行之后的位置。此检查涉及call to ResultSet#getRow(),似乎comment above中所提到的不受支持。
您可以使用JdbcCursorItemReader#setVerifyCursorPosition
禁用此检查,直到Presto驱动程序支持此功能为止。