hibernate和mybatits执行存储过程
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hibernate和mybatits执行存储过程相关的知识,希望对你有一定的参考价值。
hibernate:
private String getNewSeq(String eService) { String no = ""; Session session = getSessionFactory().openSession(); Transaction tx = null; try { tx = session.beginTransaction(); CallableStatement call = session.connection().prepareCall("{call PF_genRefNo(?,?)}"); call.setString(1, eService); call.registerOutParameter(2, Types.VARCHAR); call.execute(); no = call.getString(2); tx.commit(); } catch (SQLException e) { log.error(e.getMessage(),e); }finally{ if (session != null) { try { session.close(); } catch (HibernateException e) { log.error(e.getMessage(),e); } } } return no; }
mybatits:
public List getLocationOfVesselStatusNS(final Map paraMap){ final List retList = new ArrayList(); final String sql=" {call marinedb_ncs_p2_uat.dbo.p_PTMS_enqVslCurStatusPTMS(?)}"; Map searchMap=(Map)paraMap.get("searchMap"); final int vslId=(Integer)searchMap.get("vslId"); Object object = jdbcTemplate.execute(new CallableStatementCreator() { public CallableStatement createCallableStatement(Connection arg0) throws SQLException { CallableStatement cs = arg0.prepareCall(sql); return cs; } }, new CallableStatementCallback() { public Object doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException { cs.setInt(1, vslId); cs.execute(); List columns = new ArrayList(); columns.add("vsl_x"); columns.add("vslprev_x"); columns.add("vsllstp_x"); columns.add("vslnxp_x"); columns.add("vslcallsign_x"); columns.add("licno_x"); columns.add("vslty_x"); columns.add("vslflag_x"); columns.add("vslgt_x"); columns.add("vsllen_x"); columns.add("vsldeclrarr_x"); columns.add("vsldeclrdep_x"); columns.add("agent_x"); columns.add("mvstm_eta_x"); columns.add("mvetm_eta_x"); columns.add("mvstm_etd_x"); columns.add("mvetm_etd_x"); columns.add("currlocn_x"); columns.add("vslimo_x"); ResultSet rs = cs.getResultSet(); while (rs.next()) { Map map = new HashMap(); for (int i = 0; i < columns.size(); i++) { map.put(columns.get(i), rs.getString(i + 1)); } retList.add(map); } return retList; } }); return retList; }
以上是关于hibernate和mybatits执行存储过程的主要内容,如果未能解决你的问题,请参考以下文章
hibernate的update() 更新延迟或者无法更新,导致同个service调用存储过程执行方法不精确