【发布时间】:2016-02-04 20:21:03
【问题描述】:
我有一个运行良好的 oracle SQL 语句:
select user_id,email from app_users where user_id in (select user_id from app_users_groups where group_id = ?);
我运行它并得到了我期望的结果,但是我试图通过以下方式在 Java 中运行它:
try (Connection conn = dataSource.getConnection()) {
try (PreparedStatement ps = conn.prepareStatement("select user_id,email from app_users where user_id in (select user_id from app_users_groups where group_id = ?);")) {
ps.setInt(1, groupId);
try (ResultSet rs = ps.executeQuery()) {
while(rs.next()) {
}
}
}
} catch (SQLException e) { }
但是我在ps.executeQuery 失败并出现 SQLException ORA-00933: SQL 命令未正确结束。
我不太确定问题是什么,尽管我确定这是我缺少的一些简单的东西。
谢谢
【问题讨论】:
-
去掉查询末尾的分号
-
你应该发布堆栈跟踪
-
Dmitry 是对的:您需要删除字符串中的
;。但是您还应该在子查询中完全限定列名user_id以避免名称冲突。