bboss persistent提供了对callablestatement接口的良好封装,本文档介绍通过CallableDBUtil调用函数的使用方法。
通过位置绑定变量的方式设定函数的out参数和in参数。
java代码段:
CallableDBUtil callableDBUtil = new CallableDBUtil();
try
{
callableDBUtil.prepareCallable("{? = call Test_f(?,?,?)}");
callableDBUtil.registerOutParameter(1, java.sql.Types.INTEGER);
callableDBUtil.setInt(2, 10);
callableDBUtil.registerOutParameter(3, java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter(4, java.sql.Types.VARCHAR);
callableDBUtil.executeCallable();
System.out.println("ret:" + callableDBUtil.getInt(1));
System.out.println("name:" + callableDBUtil.getString(3));
System.out.println("name1:" + callableDBUtil.getString(4));
}
catch(Exception e)
{
e.printStackTrace();
}
Test_f函数的定义:
CREATE OR REPLACE FUNCTION test_f(id number,name out varchar2,name1 out varchar2) RETURN NUMBER IS
tmpVar NUMBER;
BEGIN
tmpVar := id;
name := 'function name hello.';
name1 := 'function name1 hello.';
RETURN tmpVar;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END test_f;
bboss项目下载列表 在sourceforge访问地址为:
https://sourceforge.net/project/showfiles.php?group_id=238653