Java异常:语句未返回结果集 [英] Java exception: the statement didn't return a resultset
问题描述
我的原始环境是 SQL Server 2005 + WebSphere v6.0(JDBC 3.0).当我如下运行程序时,它运行良好.
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();
但是,当我将环境升级到 SQL Server 2005 + WebSphere v8.5(JDBC 4.0)时,会出现错误消息:
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:语句未 返回结果集.
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();
我的问题是,有什么方法可以使我的程序保持不变,并且可以与JDBC 4.0 driver(WAS v8.5)
或SQL svr 2000 + WAS v8.5
之类的任何组合一起很好地工作.
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.
安
推荐答案
您正尝试使用INSERT
等) >. Javadoc用于该方法明确表示:
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:
抛出:SQLException-如果发生数据库访问错误,则在封闭的Statement上调用此方法,给定的SQL语句产生除单个ResultSet对象之外的任何东西
您要么需要使用executeUpdate
方法(如果它实际上是一个更新/插入/删除,要么是execute
,然后使用生成的boolean
和
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.
这篇关于Java异常:语句未返回结果集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!