我有一个运行良好的 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.P 和 a_horse_with_no_name 所说。
我只需删除分号 - 也按照建议限定列名称。
conn.prepareStatement("select u.user_id,u.email from app_users u where u.user_id in (select g.user_id from app_users_groups_xref g where g.group_id = ?)")
我只是脑残,谢谢。
关于java - ORA-00933 : SQL command not properly ended in PreparedStatement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35210855/