首页 > 代码库 > hibernate和mybatits执行存储过程
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执行存储过程
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。