I am trying to run a Stored Procedure in MSSQL via jdbc. The way I see it I have two options:
Connection conn = //Code that I know gets the correct connection
Statement stmt = conn.prepareStatement(request.query);
ResultSet resultSet = stmt.executeQuery(request.query);
Using this the query runs fine but the code throws an exception: "Error: The statement did not return a result set."
Or
PreparedStatement stmt = conn.prepareStatement(request.query);
ResultSet resultSet = stmt.executeQuery();
Which does the same thing. Are these essentially doing the same thing under the hood? I know I could use stmt.executeUpdate()
but I want to get a ResultSet
back so I can do post processing.
Which way is correct? And what can I do to guarantee a ResultSet
is returned?
I looked at this and this question and the answers were not effective/applicable.