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

原创
2015/04/22 12:20
阅读数 1.2K
  • 表结构
  • 存储过程
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;
	}
}

 

展开阅读全文
打赏
0
7 收藏
分享
加载中
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;

import com.jfinal.core.ActionKey;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.ICallback;

import oracle.jdbc.OracleTypes;

public class AccessToken extends Controller {

@ActionKey("token/get")
public void applyToken() {

Object o = Db.execute(new ICallback() {
@Override
public Object call(Connection conn) throws SQLException {
CallableStatement proc = conn.prepareCall("{?=call eops_xxx.bbb(?,?)}");
proc.registerOutParameter(1, OracleTypes.INTEGER);
proc.setString(2, "证书");
proc.registerOutParameter(3, OracleTypes.VARCHAR);
proc.execute();
return proc.getObject(3);
}
});

renderJson(o.toString()));
}

}
2017/03/29 21:59
回复
举报
更多评论
打赏
1 评论
7 收藏
0
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部