【问题标题】:org.postgresql.util.PSQLException: The column index is out of range:org.postgresql.util.PSQLException:列索引超出范围:
【发布时间】:2012-08-24 07:53:26
【问题描述】:

我正在使用 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) }));

当我执行以下查询时,我得到 The column index is out of range: 1, number of columns: 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)

谢谢,请帮帮我..

【问题讨论】:

  • 由于DO 块不是过程,我猜你不能使用CallableStatement。尝试使用常规 PrepareStatement,然后改用 execute()。如果我没记错的话,CallableStatement 严格用于存储过程。

标签: java jdbc


【解决方案1】:

错误消息表示您期望的列数比返回的列数多。

【讨论】:

    猜你喜欢
    • 2015-03-13
    • 2021-05-25
    • 1970-01-01
    • 2021-05-25
    • 1970-01-01
    • 1970-01-01
    • 2020-03-17
    • 2018-12-16
    • 2014-08-25
    相关资源
    最近更新 更多