bbedward
bbedward

Reputation: 6478

ORA-00933: SQL command not properly ended in PreparedStatement

I have an oracle SQL statement that works fine:

select user_id,email from app_users where user_id in (select user_id from app_users_groups where group_id = ?);

I run this and I get the results I expect, however I'm trying to run it in Java via the following:

    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) { }

However I fail at the ps.executeQuery with SQLException ORA-00933: SQL command not properly ended.

I'm not too sure what the issue is, although I'm sure it's something simple I'm missing.

Thanks

Upvotes: 0

Views: 3437

Answers (1)

bbedward
bbedward

Reputation: 6478

As Dmitry.P and a_horse_with_no_name said.

I just had to remove the semicolon - also qualified column names as suggested.

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 = ?)")

Simple brainfart on my part, thanks.

Upvotes: 2

Related Questions