【发布时间】:2017-03-29 21:35:22
【问题描述】:
当前尝试使用 jdbctemplate 对 oracle 数据库运行非常简单的查询,遇到以下错误:
PreparedStatementCallback; SQL 的未分类 SQLException;无效的 列类型;嵌套异常是 java.sql.SQLException: Invalid column 输入
列
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);
}
任何帮助将不胜感激。
【问题讨论】:
-
这不是想用
PrepardStatementSetteras an argument吗? (不是我用过的东西,但我无法匹配你对文档所做的事情——不过我可能遗漏了一些明显的东西!) -
我同意 Alex 的观点,但我看不到您当前的 sn-p 是如何编译的,因此您如何看到运行时
SQLException与您共享的内容。您想使用queryForMap()还是只使用query()? -
@AlexPoole 重读文档后,您可以使用 PreparedStatementSetter 作为我广泛使用的 query() 中的参数,但不能在 queryformap() 中使用,这将是我的问题所在。至于为什么编译?显然 PreparedStatementSetter 算作一个有效的对象数组,尽管它实际上并没有提供任何值。我已经切换到 query() 并且事情现在按预期工作。感谢你和米克。
标签: java oracle jdbctemplate