查询操作、存储过程、函数调用中使用行处理器-bboss persistent框架行处理器使用-1

 查询操作、存储过程、函数调用中使用行处理器-bboss persistent框架行处理器使用-1

 

存储过程中使用行处理器-RowHandle接口,自己管理和处理out参数。下面的示例是将存储过程test_p的out参数通过行处理器处理后再设置到java对象Test_p中,应用程序得到的将是经过行处理器处理过的java对象。

 

存储过程定义如下:

 

CREATE OR REPLACE PROCEDURE test_p(id in number,
                name out varchar2
         ,name1 out varchar2,test out number
         ,nomatch out number) IS

/******************************************************************************
   NAME:       test
   PURPOSE:   

   REVISIONS:
   Ver        Date        Author           Description
   ---------  ----------  ---------------  ------------------------------------
   1.0        2008-10-27          1. Created this procedure.

   NOTES:

   Automatically available Auto Replace Keywords:
      Object Name:     test
      Sysdate:         2008-10-27
      Date and Time:   2008-10-27, 17:05:33, and 2008-10-27 17:05:33
      Username:         (set in TOAD Options, Procedure Editor)
      Table Name:       (set in the "New PL/SQL Object" dialog)

******************************************************************************/
BEGIN
   --tmpVar := 0;
   name := 'hello name';
   name1 := 'hello name1';
   test := id;
   --insert into test(id,name) values(SEQ_TEST.nextval,'name1');
   commit;
  
  
EXCEPTION
  WHEN NO_DATA_FOUND THEN
    NULL;
  WHEN OTHERS THEN
    -- Consider logging the error and then re-raise
    RAISE;
END test_p;
/

 

java对象Test_p:

 

public class Test_p {
 private String test;
 private String name;
 private String name1;
 private int count = 0;
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public String getName1() {
  return name1;
 }
 public void setName1(String name1) {
  this.name1 = name1;
 }
 public String toString()
 {
  return new StringBuffer().append("name=").append(name).append(",name1=").append(name1).append(",test=").append(test).toString();
 }
 public String getTest() {
  return test;
 }
 public void setTest(String test) {
  this.test = test;
 }
 public int getCount() {
  return count;
 }
 public void setCount(int count) {
  this.count = count;
 }

}

 

行处理器的处理过程如下:

 

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);
   Test_p tets = (Test_p)callableDBUtil.executeCallableForObject(Test_p.class,new RowHandler(){

    public void handleRow(Object rowValue, Record record) {
     Test_p test_p = (Test_p)rowValue;
     try {
      test_p.setTest(record.getString("test")+"天马");
      test_p.setName1(record.getString("name1"));
      test_p.setName(record.getString("name"));
     } catch (SQLException e) {
      e.printStackTrace();
     }
    }
    
   });
   

   
   System.out.println("Test_p is " + tets);
     
  }
  catch(Exception e)
  {
   e.printStackTrace();
  } 

 

 

代码相当简单。

 

 

bboss项目下载列表 在sourceforge访问地址为:
https://sourceforge.net/project/showfiles.php?group_id=238653

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值