请教一下 真的很着急 jdbc 取得返回值 急急急
create PROCEDURE str_getanswer1(@PVNO VARCHAR(8))
AS
BEGIN
declare @answer INT;
IF (@PVNO='abc')
BEGIN
SET @answer=8
END
ELSE
BEGIN
SET @answer=7
END
RETURN @answer
END
后台java代码 怎么取得@answer返回值
cs = conn.prepareCall("{call str_getanswer(?)}");
不知道怎么取得返回值
[解决办法]
你先把存储过程写对了再说。
out 是存储过程
return是函数
[解决办法]
cstmt = conn.prepareCall("begin test(?,?); end;");
cstmt.setInt(1, deptno);
cstmt.registerOutParameter(2, OracleTypes.CURSOR);
cstmt.execute();
rs = (ResultSet) cstmt.getObject(2);
ResultSetMetaData rsm = rs.getMetaData();
int columnCount = rsm.getColumnCount();
while (rs.next()){
for (int j=0;j< columnCount;j++){
temp = rs.getObject(j+1);
}
}
callableStatement = connection.prepareCall("{ call zhangbo.pro_input_output(?,?) }");
callableStatement.setInt(1, 7521);//输入参数
callableStatement.registerOutParameter(2, Types.VARCHAR);//输出参数
callableStatement.execute();//执行存储过程
String name = callableStatement.getString(2);//获取输出参数
System.out.println("编号7521的员工姓名为: " + name);
SELECT 'Return Value' = @answer
prepareStatement("{call xxxx(?)}");
stmt.setString(1, customerId);
rs = stmt.executeQuery();
if (rs.next()) {
rs.getString("Return Value");
}