JdbcTemplate 嵌套查询的问题

发布于 2024-12-03 03:55:06 字数 1008 浏览 0 评论 0原文

我正在尝试将嵌套查询与 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

方圜几里 2024-12-10 03:55:06

尝试将 upper('?') 更改为 upper(?)。通过将 ? 放在引号中,数据库不会意识到您正在处理参数。

Try changing the upper('?') to upper(?). By putting the ? in quotes, the database doesn't realize that you're dealing with a parameter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文