The problem occurs when executeQuery function runs, the sql statement is work correctly and gives correct results when it is runned on the sql editor. When it is runned on jdbc
Have a look at the following documentation which explains to use execute()
instead of executeQuery()
and then fire a getResultSet()
on the Result set that you get.
The whole approach is to change your query into a Stored procedure and invoke the same through a CallableStatement
.
Documentation suggests:
Although CallableStatement supports calling any of the Statement execute methods (executeUpdate(), executeQuery() or execute()), the most flexible method to call is execute(), as you do not need to know ahead of time if the stored procedure returns result sets.
Hope this helps!