转自:http://blog.csdn.net/kirbylynx/archive/2008/12/09/3483449.aspx
比如SQL Server的一个存储过程:
create procedure proc_test
@q_type int,
@value int,
@count int output
as
begin
update mytable set value = @value where type = @q_type
set @count = @@rowcount
select * from mytable where type = @q_type
end
go
这个存储过程,既有输出参数,又有返回结果集,而用java调用他,两者都要取到,则代码如下:
Connection conn = MyConnectionPool.getConnection();
CallableStatement cstmt = conn.prepareCall("{call proc_test(?,?,?)}");
cstmt.setInt(1, type);
cstmt.setInt(2, value);
cstmt.registerOutParameter(3, java.sql.Types.INTEGER);
ResultSet rs = cstmt.executeQuery();
while(rs.next()) {
doSomeThingToResultSet(rs