如果我在存储过程中选择之前进行更新,有没有人知道为什么我得不到结果集。我正在运行 MSSQL server 2005 和最新的 Microsoft JDBC 驱动程序。
相关java代码:
CallableStatement cstmt = con.prepareCall("{call dbo.sp_groups_select}");
if (cstmt.execute()) {
while (cstmt.getResultSet().next())
如果存储过程如下所示,则不会获得结果集:
CREATE PROCEDURE [dbo].[sp_groups_select] AS
update Computers set ComputerName='Foo' where ComputerName='bar';
select * from Computers;
但如果看起来像这样,我会得到一个结果集
CREATE PROCEDURE [dbo].[sp_groups_select] AS
select * from Computers;
update Computers set ComputerName='Foo' where ComputerName='bar';
最佳答案
可能是因为您需要 SET NOCOUNT ON
(x rows affected)
等效项在客户端中作为结果集进行处理,这使 cstmt.getResultSet().next()
我关于SET NOCOUNT ON的问题的无耻插件
关于java - 如果存储过程在 MSSQL Server 2005 上的选择之前进行更新,则没有结果集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4809719/