无法执行NamedParameterJdbcTemplate UPDATE

时间:2016-08-23 16:14:18

标签: spring-jdbc snappydata

我正在尝试通过JDBC API和Spring的NamedParameterJdbcTemplate对SnappyData行表执行UPDATE。

错误是:

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'.**
    at com.pivotal.gemfirexd.internal.shared.common.error.DefaultExceptionFactory40.getSQLException(DefaultExceptionFactory40.java:121)
    at com.pivotal.gemfirexd.internal.shared.common.error.ExceptionUtil.newSQLException(ExceptionUtil.java:148)
    at com.pivotal.gemfirexd.internal.client.am.SqlException.getSQLException(SqlException.java:419)
    at com.pivotal.gemfirexd.internal.client.am.ColumnMetaData.getColumnType(ColumnMetaData.java:644)
    at com.pivotal.gemfirexd.internal.client.am.PreparedStatement.setString(PreparedStatement.java:1203)
    at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.setString(HikariProxyPreparedStatement.java)
    at org.springframework.jdbc.core.StatementCreatorUtils.setValue(StatementCreatorUtils.java:429)
    at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal(StatementCreatorUtils.java:235)
    at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(StatementCreatorUtils.java:150)
    at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.setValues(PreparedStatementCreatorFactory.java:292)
    at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.createPreparedStatement(PreparedStatementCreatorFactory.java:244)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:623)
    ... 70 more
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)

NamedParameter SQL如下所示:

UPDATE generic_table_10 SET (VERSION = :version, FK_1 = :fk , COL_1 = :col1, COL_2 = :col2, COL_3 = :col3, COL_4 = :col4, COL_5 = :col5, COL_6 = :col6, COL_7 = :col7, COL_8 = :col8, COL_9 = :col9, COL_10 = :col10) WHERE (ID = :id and VERSION = :oldVersion)
  

注意:VERSION列类型是整数。列的其余部分   types是String。

SQL看起来像这样,这对我来说似乎没问题:

UPDATE generic_table_10 SET (VERSION = ?, FK_1 = ? , COL_1 = ?, COL_2 = ?, COL_3 = ?, COL_4 = ?, COL_5 = ?, COL_6 = ?, COL_7 = ?, COL_8 = ?, COL_9 = ?, COL_10 = ?) WHERE (ID = ? and VERSION = ?)

1 个答案:

答案 0 :(得分:0)

我自己解决了这个问题......语法很糟糕。我删除了括号,现在可以使用了。现在是SQL:

UPDATE generic_table_10 SET VERSION = ?, FK_1 = ? , COL_1 = ?, COL_2 = ?, COL_3 = ?, COL_4 = ?, COL_5 = ?, COL_6 = ?, COL_7 = ?, COL_8 = ?, COL_9 = ?, COL_10 = ? WHERE ID = ? and VERSION = ?

我必须说,尽管我缺乏SQL语法技能,但错误信息有点误导!