Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
252 views
in Technique[技术] by (71.8m points)

java - No resultset if the store procedures does an update before the select on MSSQL server 2005

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.

Relevant java code:

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';
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Probably because you need SET NOCOUNT ON

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

Shameless plug of my question about SET NOCOUNT ON


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...