在S2SH中调用返回参数的存储过程

在SqlServer中创建存储过程:

create proc test
@result int output  ---输出参数
as
begin
declare @test varchar(50)
declare @count int
select @test='this is test proc result:'
select @count = count(*) from GOODSCODE
set @result=@count
print @test
print @count
end

其实,Hibernate中还没发现,其集成处理存储过程的方法,但是可通过Session获得对数据库的连接,走Java调用存储过程的路线

service代码如下:

 public List sqlQuery() {
  Connection connection = null;
  CallableStatement statement = null;
  ResultSet rs = null;
  connection=factory.getCurrentSession().connection();
  try {
   statement = connection.prepareCall("{Call test(?)}");
   statement.registerOutParameter(1, java.sql.Types.INTEGER);
   statement.execute();
   System.out.println(statement.getInt(1));
  } catch (SQLException e) {
   e.printStackTrace();
  }


  
  
  return null;
 }

posted @ 2013-04-27 15:19  七星6609  阅读(272)  评论(0编辑  收藏  举报