读书人

Hibernate 调用存储过程(2)

发布时间: 2012-09-22 21:54:54 作者: rapoo

Hibernate 调用存储过程(二)

前面有一篇文章介绍过一次hibernate调用存储过程

上次的存储过程。是直接两个参数返回结果集。

这次有所不同。参数里面带有out输出参数。来返回的结果集。

找了很久发现hibernate是不直接支持out参数的。。

在这里只能有JDBC了。

?

public List<SearchReportDto1061> shishiCount(String dwbh, String date){ List<SearchReportDto1061> list = new ArrayList<SearchReportDto1061>(); Connection con = getSession().connection();//通过hibernate得到的连接        String sql="{Call statistics_report.report_31_calc(?,?,?)}";     ResultSet  rs = null;     try {    CallableStatement cs = con.prepareCall(sql);cs.registerOutParameter(1, oracle.jdbc.OracleTypes.CURSOR);//out参数cs.setString(2, dwbh);    cs.setString(3, date);    rs=cs.executeQuery();   rs=(ResultSet)cs.getObject(1);    while(rs.next())    {    SearchReportDto1061 entity=new SearchReportDto1061();    entity.setVaccineCode(rs.getString(1));    entity.setInjectionno(rs.getString(2));    entity.setLocalShouldNumber(rs.getInt(3));    entity.setLocalInoculatedNumber(rs.getInt(4));    entity.setOutlandshouldnumber(rs.getInt(5));    entity.setOutlandinoculatednumber(rs.getInt(6));    list.add(entity);    }} catch (SQLException e) {e.printStackTrace();}return list; }

?

读书人网 >编程

热点推荐