java调用存储过程返回参数

CREATE PROCEDURE [dbo].[sp_insertStudent](@name char(10),@age int,@id int OUTPUT) AS
insert into Students([Name],[Age]) values (@name,@age)
select @id=@@IDENTITY –测试输出参数
return 30 –测试返回30
GO

??? try {
????? pstmt = con.prepareCall("{?=call sp_insertStudent(?,?,?)}");
????? pstmt.setString(2, "zengqingsong");
????? pstmt.setInt(3, 22);

????? pstmt.registerOutParameter(4, Types.INTEGER);
????? pstmt.registerOutParameter(1, Types.INTEGER);
????? int ret = pstmt.executeUpdate(); //执行影响的行数

????? int ret2 = pstmt.getInt(1); //返回参数(输出参数)
????? int id = pstmt.getInt(4); //输出参数
????? System.out.println(ret);
????? System.out.println(ret2);
????? System.out.println(id);
??? }

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页