SnappyData JDBC 驱动程序引发 SQLState=XCL14 错误

SnappyData JDBC driver raising SQLState=XCL14 error

带 ClientDriver JDBC 驱动程序的 SnappyData v.0-5。

我在 SnappyData 中有一个持久行 table,名为:sensor_data。

来自 snappy> shell,此查询 returns 千行。

snappy> select * from sensor_data where year_num = 2013 and month_num = 1;

当 运行 来自 Spring 引导中的 JDBC 连接时,我收到此错误:

PreparedStatementCallback; uncategorized SQLException for SQL [select * from sensor_data where year_num = ? and month_num = ?]; SQL state [XCL14]; error code [20000]; (SQLState=XCL14 Severity=20000) The column position '1' is out of range. The number of columns for this ResultSet is '0'.

Java 代码为:

List<SensorData> list = jdbcTemplateBean.query("select * from sensor_data where year_num = ? and month_num = ?", 
                new Object[] {year, month},  new SensorDataRowMapper());

我需要做什么来解决这个 JDBC 问题?

在 Spring 启动时修剪 Stacktrace:

org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [select * from sensor_data where year_num = ? and month_num = ?]; SQL state [XCL14]; error code [20000]; (SQLState=XCL14 Severity=20000) The column position '1' is out of range. The number of columns for this ResultSet is '0'.; nested exception is java.sql.SQLException: (SQLState=XCL14 Severity=20000) The column position '1' is out of range. The number of columns for this ResultSet is '0'. at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:84) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:645) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:680) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:707) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:757) at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.query(NamedParameterJdbcTemplate.java:192) at org.kritek.scalability.repository.SensorDataRepository.findByYearAndMonth(SensorDataRepository.java:58) ... at org.eclipse.jetty.util.thread.QueuedThreadPool.run(QueuedThreadPool.java:555) at java.lang.Thread.run(Thread.java:745) Caused by: java.sql.SQLException: (SQLState=XCL14 Severity=20000) The column position '1' is out of range. The number of columns for this ResultSet is '0'. ... Caused by: ERROR XCL14: The column position '1' is out of range. The number of columns for this ResultSet is '0'. at com.pivotal.gemfirexd.internal.client.am.ColumnMetaData.checkForValidColumnIndex(ColumnMetaData.java:856) at com.pivotal.gemfirexd.internal.client.am.ColumnMetaData.getColumnType(ColumnMetaData.java:638) ... 72 more

从堆栈看,似乎正在使用 NamedParameterJdbcTemplate,但是“?”正在使用占位符。对于 NamedParameterJdbcTemplate you need to use named parameters like here.

我会推荐使用标准'?' JdbcTemplate 的占位符机制,例如:

private JdbcTemplate jdbcTemplateBean;

public void setDataSource(DataSource dataSource) {
  this.jdbcTemplateBean = new JdbcTemplate(dataSource);
}

List<SensorData> list = jdbcTemplateBean.query(
    "select * from sensor_data where year_num = ? and month_num = ?",
    new Object[] { year, month },  new SensorDataRowMapper());

问题已解决。这是发生了什么...... SnappyData 将查询路由到 Spark,因为它确定它无法处理它。 Spark 对 JDBC PreparedStatements 或绑定变量一无所知并引发了错误。要修复,我必须在我的数据源配置中设置 SnappyData JDBC 属性 "route-query = false"。这确保它不会被路由到 Spark。