首页 > Web开发 > 详细

hibernate和mybatits执行存储过程

时间:2017-04-06 11:52:18      阅读:291      评论:0      收藏:0      [点我收藏+]

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执行存储过程

原文:http://www.cnblogs.com/donnieluo/p/6672685.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!