如果存储过程在MSSQL服务器2005上的选择之前执行更新,则无结果集 [英] No resultset if the store procedures does an update before the select on MSSQL server 2005

查看:93
本文介绍了如果存储过程在MSSQL服务器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行受影响)等价物作为结果集处理客户端,bollixes cstmt.getResultSet()。next()

The (x rows affected) equivalent is processed as a resultset in the client, which bollixes cstmt.getResultSet().next()

关于 SET NOCOUNT ON

Shameless plug of my question about SET NOCOUNT ON

这篇关于如果存储过程在MSSQL服务器2005上的选择之前执行更新,则无结果集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆