码迷,mamicode.com
首页 > 数据库 > 详细

JFinal调用Oracle存储过程返回结果集

时间:2015-04-22 14:08:17      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

  • 表结构
技术分享
  • 存储过程
CREATE OR REPLACE PROCEDURE TEST3(TID IN INTEGER,O OUT SYS_REFCURSOR)
AS 
BEGIN
  IF(TID>0) THEN 
    OPEN O FOR SELECT * FROM XHSCK.T_ADMINISTRATIVE_LEVEL T WHERE T.ADMINISTRATIVE_LEVEL_ID = TID;
  ELSE
    OPEN O FOR SELECT * FROM XHSCK.T_ADMINISTRATIVE_LEVEL T WHERE T.ADMINISTRATIVE_LEVEL_ID = 1;
  END IF;
END;

  • Java代码(调用类)

 

WallFilter wallFilter = new WallFilter();
DruidPlugin druid = new DruidPlugin(getProperty("jdbc.url"),
		getProperty("jdbc.username"),
		getProperty("jdbc.password").trim()
		  ,getProperty("jdbc.driver"));
druid.addFilter(new StatFilter());
druid.addFilter(wallFilter);
//连接池最大使用连接数量 
druid.setMaxActive(getPropertyToInt("maxActive",100));
//连接池最小空闲
druid.setMinIdle(getPropertyToInt("minIdle",10));
//初始化大小 
druid.setInitialSize(getPropertyToInt("initialSize",10));
druid.start();
Config cfg = new Config("1", druid.getDataSource());
DbKit.addConfig(cfg);
List<Record> list = (List<Record>) Db.use("1").execute(new MyCallBack(6,cfg));
System.out.println(list.get(0).getStr("ADMINISTRATIVE_LEVEL_NAME"));

  • Java代码(回调类)
public class MyCallBack implements ICallback {
	public int tid;
	public Config cfg;
    public ResultSet rs = null;
    MyCallBack(int tid,Config cfg){
    	this.tid=tid;
    	this.cfg=cfg;
    }
	@Override
	public Object call(Connection conn) throws SQLException {
		CallableStatement proc = null;
         proc = conn.prepareCall("{ call test3(?,?) }");
         proc.setInt(1, tid);
         proc.registerOutParameter(2, OracleTypes.CURSOR);
         proc.execute();
         ResultSet s =  (ResultSet) proc.getObject(2);
         List<Record> list = (List<Record>) RecordBuilder.build(cfg, s);
         return list;
	}
}

 

JFinal调用Oracle存储过程返回结果集

标签:

原文地址:http://my.oschina.net/forai/blog/405000

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!