ResultSet is from UPDATE. No Data

前端 未结 3 1882
后悔当初
后悔当初 2021-01-24 08:46

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

相关标签:
3条回答
  • 2021-01-24 09:08

    This is not possible, you have to separate your queries, of for the best solution you can use procedures or function.

    1. Procedure should take lectureID
    2. Return your result, in your case it should multiples valus, you can read How to retrieve multiple rows from stored procedure in mysql? to know how to use procedure return multiple values
    0 讨论(0)
  • 2021-01-24 09:19

    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!

    0 讨论(0)
  • 2021-01-24 09:30

    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

    0 讨论(0)
提交回复
热议问题