简单计数查询上的Oracle无效列

时间:2016-11-15 20:46:54

标签: java oracle jdbctemplate

目前正在尝试使用 jdbctemplate 对oracle db运行一个非常简单的查询,遇到以下错误:

  

PreparedStatementCallback;未分类SQL的SQLException;无效   列类型;嵌套异常是java.sql.SQLException:无效列   型

SYSTEM_UNIQUE_ID   VARCHAR2(50 CHAR)
SYSTEM_TYPE_ID      NUMBER(4,0)

致电

public int getSystemUniqueIDCount(final String systemUniqueID, final String systemTypeID) throws SQLException {

    String checkCountQuery = "select count(*) as count from master_account where system_unique_id = ? and system_type_id = ?";

    Map<String, Object> row = getTemplate().queryForMap(checkCountQuery , new PreparedStatementSetter() {

        @Override
        public void setValues(PreparedStatement pstmt) throws SQLException {
            pstmt.setString(1, systemUniqueID.toUpperCase());
            pstmt.setInt(2, Integer.parseInt(systemTypeID));
        }

    });

    return (int) row.getOrDefault("count", 0);
}

任何帮助都会受到很大关注。

1 个答案:

答案 0 :(得分:0)

queryForMap()不会将PreparedStatementSetter()作为参数,而是在我的情况下假设它是一个对象[]。这意味着它试图将preparedstatementsetter本身的值作为查询中的参数插入,这显然会爆炸。

感谢Mike Mnemonic和Alex Poole。