Java exception: the statement didn't return a resultset

被刻印的时光 ゝ 提交于 2021-02-05 09:45:22

问题


My original environment is SQL server 2005 + WebSphere v6.0(JDBC 3.0). When I run the program as below and it works well.

ResultSet rs=stmt.executeQuery(sql);
rs.next();

However, when I upgrade the environment to SQL server 2005 + WebSphere v8.5(JDBC 4.0), I get the error message:

com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.

From this forum's information, it seems that I have multiple resultsets, so I try to change the program as follows and it works fine.

stmt.execute(sql);
stmt.getMoreResults();
stmt.getMoreResults();
ResultSet rs=stmt.getResultSet();
rs.next();

My questions is that is there any approach that I can keep my program unchanged and works well with JDBC 4.0 driver(WAS v8.5) or any combination like SQL svr 2000 + WAS v8.5, etc.

Please give me any pointer and your recommendation is valuable to me, thank you.

Ann


回答1:


You are attempting to execute a query that either produces multiple resultsets or that does not produce a resultset (eg UPDATE, INSERT etc) using executeQuery. The Javadoc for this method explicitly says:

Throws: SQLException - if a database access error occurs, this method is called on a closed Statement, the given SQL statement produces anything other than a single ResultSet object

You either need to use the executeUpdate method (if it is actually an update/insert/delete, or execute and then use the resulting boolean and that of getMoreResults() to decide how to proceed.



来源:https://stackoverflow.com/questions/14170467/java-exception-the-statement-didnt-return-a-resultset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!