日期:2014-05-18  浏览次数:20427 次

[跪求帮助]关于SQL存储过程的问题.调试存储过程是正常的,但在程序里调用得不到结果集
CREATE PROCEDURE [dbo].[wbjl_ms_add]
@userid char(20) ,
@rid char(20) ,
@content char(400) ,
@jobtag char(20)
as
declare @retcode int,@retdesc char(50)
select @retcode=1,@retdesc='账号异常,请重新登陆'

if exists(select 1 from tbl_user where userd and rid=@rid)
begin
  insert into tbl_ms(userid,rid,content,jobtag) values(@userid,@rid,@content,@jobtag)
  if(@@error=0)
  begin
  select @retcode=0,@retdesc='发布成功'
  end
  else
  begin
  select @retcode=-1,@retdesc='数据库错误'
  end
end
select @retcode as retcode,@retdesc as retdesc

上面这个存储过程,我在SQL management里调试是正常的,返回的retdesc能正常显示,
但在JSP里调用这个存储过程,rs得不到结果集,无论是statement和preparement都不行.
我怀疑是不是sqljdbc的版本问题?换了很多个SQLJDBC,解决不了问题.
SQL版本是2005的,求帮助

------解决方案--------------------
SQL code
你可以使用带输出参数的存储过程

CREATE PROCEDURE [dbo].[wbjl_ms_add]
@userid char(20) ,
@rid char(20) ,
@content char(400) ,
@jobtag char(20),
@retcode int output,
@retdesc varchar(100) output
as
declare @retcode int,@retdesc char(50)
select @retcode=1,@retdesc='账号异常,请重新登陆'

if exists(select 1 from tbl_user where userd and rid=@rid)
begin
  insert into tbl_ms(userid,rid,content,jobtag) values(@userid,@rid,@content,@jobtag)
  if(@@error=0)
  begin
  select @retcode=0,@retdesc='发布成功'
  end
  else
  begin
  select @retcode=-1,@retdesc='数据库错误'
  end
end