Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java org.postgresql.util.PSQLException:列索引超出范围:_Java_Jdbc - Fatal编程技术网

Java org.postgresql.util.PSQLException:列索引超出范围:

Java org.postgresql.util.PSQLException:列索引超出范围:,java,jdbc,Java,Jdbc,我使用的是spring JDBC模板 Map resultsMap = getStoryJdbcTemplate().call( new CallableStatementCreator() { public CallableStatement createCallableStatement(Connection pConn) throws SQLException { CallableStatement callable = p

我使用的是spring JDBC模板

    Map resultsMap = getStoryJdbcTemplate().call(
    new CallableStatementCreator() {

      public CallableStatement createCallableStatement(Connection pConn)
          throws SQLException {
        CallableStatement callable = pConn.prepareCall(DELETE_STORY);
        callable.setLong(1, pStory.getId());
        callable.setLong(2, pStory.getVersion());
        callable.registerOutParameter(3, Types.INTEGER);
        callable.registerOutParameter(4, Types.BIGINT);
        return callable;
      }
    },
    Arrays.asList(new SqlParameter[] { new SqlParameter(Types.BIGINT), 
        new SqlParameter(Types.BIGINT),
        new SqlOutParameter("rowCount", Types.INTEGER), 
        new SqlOutParameter("version", Types.BIGINT) }));
当我执行以下查询时,我发现列索引超出范围:1,列数:0。;嵌套异常是org.postgresql.util.PSQLException

    private static final String DELETE_STORY = ""

+"Do $$"      
+ "DECLARE "
+ "   v_rowcount numeric; "
+ "   v_version numeric; "
+ "BEGIN "
+ "     DELETE FROM registrant_stories "
+ "     WHERE registrant_story_id = ? AND version = ? "
+ "     RETURNING version INTO v_version; "
+ "     GET DIAGNOSTICS v_rowcount := ROW_COUNT; "
+ "     ? := v_rowcount; "
+ "     ? := v_version; "
+ "END $$ ; ";
错误跟踪是:

   org.springframework.dao.DataIntegrityViolationException: CallableStatementCallback; SQL []; The column index is out of range: 1, number of columns: 0.; nested exception is org.postgresql.util.PSQLException: The column index is out of range: 1, number of columns: 0.
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:100)

Thanx,请帮帮我。

错误消息意味着您期望的列数比返回的列数多。

错误消息意味着您期望的列数比返回的列数多。

由于
DO
块不是一个过程,我猜您不能使用CallableStatement。尝试使用常规的PrepareStatement,然后改为执行()。如果我没有弄错的话,CallableStatement是严格用于存储过程的。由于
DO
块不是过程,我想您不能使用CallableStatement。尝试使用常规的PrepareStatement,然后改为执行()。若我并没有弄错的话,CallableStatement严格适用于存储过程。