JdbcTemplate 嵌套查询的问题
我正在尝试将嵌套查询与 JdbcTemplate 一起使用,但发现了问题,在我看来,它不支持嵌套查询。我对吗?或者我需要改变什么?
所以,我调用
getJdbcTemplate().query(request, new Object[]{name}...)
// request is query which you can see in error message
它在 oracle 中给出结果但失败了
org.springframework.jdbc.InvalidResultSetAccessException:PreparedStatementCallback; SQL 的结果集访问无效[select sq.name as name from (select t1.name as name from table1 t1 left external join table2 t2 on t2.id = t1.fk_id where t1.name is not null ) sq where upper (名称)如上('?')];嵌套异常是 java.sql.SQLException:无效的列索引
EDITED
请求是一个简单的String对象,它实际上是您在异常消息中看到的sql。在这种情况下,eturn 对象没有任何关系,因为我将其留空(用于测试我们的姿势),
但只是为了让您确定它是:
List<MyObject> list = getJdbcTemplate().query(request, new Object[]{"Somename"}, new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
return new MyObject();
}
});
I'm trying to use nested queries with JdbcTemplate but found the issue, it seems to me that it's doesn't suppot nested queries.. Am i right? or what i need to change?
So, i invoke
getJdbcTemplate().query(request, new Object[]{name}...)
// request is query which you can see in error message
which gives results in oracle but failes with
org.springframework.jdbc.InvalidResultSetAccessException: PreparedStatementCallback; invalid ResultSet access for SQL [select sq.name as name from (select t1.name as name from table1 t1 left outer join table2 t2 on t2.id = t1.fk_id where t1.name is not null ) sq where upper(name) like upper('?')]; nested exception is java.sql.SQLException: Invalid column index
EDITED
request is a simple String object which is actually an sql that you see in exception message. The eturn object has no matter in this situation as i left it empty (for testing ourpose)
but just for you to be sure here it is:
List<MyObject> list = getJdbcTemplate().query(request, new Object[]{"Somename"}, new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
return new MyObject();
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将
upper('?')
更改为upper(?)
。通过将?
放在引号中,数据库不会意识到您正在处理参数。Try changing the
upper('?')
toupper(?)
. By putting the?
in quotes, the database doesn't realize that you're dealing with a parameter.