bboss persistent框架可以将存储过程的out参数返回的值封装成xml格式化串返回给调用程序,本文档介绍这种使用方法.
xml的语法如下:
<?xml version="1.0" encoding="gb2312"?>
<records> --返回记录集的根节点
<record> --具体的记录的起点,存储过程只有一条记录集
<column name="name" type="VARCHAR" javatype="String">--记录中的列信息和值,包括列名,列对应java类型和表字段类型
<![CDATA[hello name]]>--列的值
</column>
<column name="name1" type="VARCHAR" javatype="String">
<![CDATA[hello name1]]>
</column>
<column name="test" type="INTEGER" javatype="int">
<![CDATA[10]]>
</column>
</record>
</records>
java代码段:
import com.frameworkset.common.poolman.CallableDBUtil;
。。。。。。
CallableDBUtil callableDBUtil = new CallableDBUtil();
try
{
callableDBUtil.prepareCallable("{call test_p(?,?,?,?)}");
//不允许的操作: Ordinal binding and Named binding cannot be combined!
callableDBUtil.setInt("id", 10);
callableDBUtil.registerOutParameter("name", java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter("name1", java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter("test", java.sql.Types.INTEGER);
String xmlString = callableDBUtil.executeCallableForXML();
System.out.println("xmlString:/r/n" + xmlString);
}
catch(Exception e)
{
e.printStackTrace();
}
执行上述代码的输出为:
xmlString:
<?xml version="1.0" encoding="gb2312"?>
<records>
<record>
<column name="name" type="VARCHAR" javatype="String">
<![CDATA[hello name]]>
</column>
<column name="name1" type="VARCHAR" javatype="String">
<![CDATA[hello name1]]>
</column>
<column name="test" type="INTEGER" javatype="int">
<![CDATA[10]]>
</column>
</record>
</records>
存储过程的定义如下:
CREATE OR REPLACE PROCEDURE test_p(id in number,
name out varchar2
,name1 out varchar2,test out number) IS
BEGIN
--tmpVar := 0;
name := 'hello name';
name1 := 'hello name1';
test := id;
commit;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END test_p;
bboss项目下载列表 在sourceforge访问地址为:
https://sourceforge.net/project/showfiles.php?group_id=238653