Jfinal调用存储过程方法

来源:互联网 发布:女生都穿安全裤 知乎 编辑:程序博客网 时间:2024/06/10 00:42

Jfinal框架目前处于比较火热的使用中,针对jfinal如何调用存储过程,在我之前开发的项目中,我是如下使用的,亲测有效!

public String getPartyMonthStatistics(String param) {        final Map<String, Object> map = new HashMap<String, Object>();        JSONObject jo = JSONObject.fromObject(param);        String domain = jo.getString("domain");        final String member_id = jo.getString("member_id");        Db.use(domain+"_r").execute(new ICallback() {            @Override            public Object call(Connection conn) throws SQLException {                CallableStatement proc = null;                try {                    proc = conn.prepareCall("{call partymonthstatistics(?,?,?,?,?)}");                    proc.setString(1, member_id);                    proc.registerOutParameter(2, java.sql.Types.VARCHAR);                    proc.registerOutParameter(3, java.sql.Types.VARCHAR);                    proc.registerOutParameter(4, java.sql.Types.VARCHAR);                    proc.registerOutParameter(5, java.sql.Types.VARCHAR);                    proc.execute();                    map.put("party_zch", proc.getString(2));                    map.put("party_zdl", proc.getString(3));                    map.put("party_xxjy", proc.getString(4));                    map.put("party_yxl", proc.getString(5));                } catch (Exception e) {                    e.printStackTrace();                }finally{                    if(proc!=null){                        proc.close();                    }                    if(conn!=null){                        conn.close();                    }                }                return null;            }        });        return JsonKit.toJson(map);    }

Db的execute方法里还是调用了底层的Connection的prepareCall(“{call partymonthstatistics(?,?,?,?,?)}”),其中partymonthstatistics是数据库当中编写的存储过程名。

原创粉丝点击