如果存储过程在 MSSQL Server 2005 上的选择之前执行更新,则没有结果集 [英] No resultset if the store procedures does an update before the select on MSSQL server 2005
本文介绍了如果存储过程在 MSSQL Server 2005 上的选择之前执行更新,则没有结果集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我在存储过程中的选择之前进行更新,有没有人知道为什么我不会得到结果集.我运行的是 MSSQL Server 2005 和最新的 Microsoft JDBC 驱动程序.
Does any one have any idea why I wont get a resultset if I do an update before the select in a store procedure. Im running MSSQL server 2005 and the latest Microsoft JDBC driver.
相关java代码:
CallableStatement cstmt = con.prepareCall("{call dbo.sp_groups_select}");
if (cstmt.execute()) {
while (cstmt.getResultSet().next())
如果存储过程如下所示,则不会获得结果集:
Does not get a resultset if the store procedure looks like this:
CREATE PROCEDURE [dbo].[sp_groups_select] AS
update Computers set ComputerName='Foo' where ComputerName='bar';
select * from Computers;
但如果看起来像这样,我确实得到了一个结果集
But if it looks like this I do get a resultset
CREATE PROCEDURE [dbo].[sp_groups_select] AS
select * from Computers;
update Computers set ComputerName='Foo' where ComputerName='bar';
推荐答案
可能是因为你需要 SET NOCOUNT ON
(x rows changed)
等价物在客户端作为结果集进行处理,这将 cstmt.getResultSet().next()
The (x rows affected)
equivalent is processed as a resultset in the client, which bollixes cstmt.getResultSet().next()
这篇关于如果存储过程在 MSSQL Server 2005 上的选择之前执行更新,则没有结果集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文