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
This is not possible, you have to separate your queries, of for the best solution you can use procedures or function.
lectureID
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!
I am not familiar with JDBC but a quick search suggests you should use execute
rather than executeQuery
.
execute: Returns true if the first object that the query returns is a ResultSet object. Use this method if the query could return one or more ResultSet objects. Retrieve the ResultSet objects returned from the query by repeatedly calling Statement.getResultSet.
https://docs.oracle.com/javase/tutorial/jdbc/basics/processingsqlstatements.html#executing_queries