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

  • 表结构
技术分享
  • 存储过程
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;
	}
}

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。