j2ee之存储过程调用
/* * 存储过程调用 */ public Object findCallByNativeSql(final String sql ,final int resultType , final Object... values) { return (Object) getHibernateTemplate().execute(new HibernateCallback<Object>() { @Override public Object doInHibernate(Session session) throws HibernateException { try { Connection connection = SessionFactoryUtils.getDataSource(session.getSessionFactory()).getConnection(); CallableStatement prepareCall = connection.prepareCall(sql); if (values != null) { for (int i = 1; i < values.length + 1; i ++) { prepareCall.setObject(i, values[i-1]); } } prepareCall.registerOutParameter(values.length + 1, resultType); prepareCall.execute(); return prepareCall.getObject(values.length + 1); } catch (SQLException e) { e.printStackTrace(); return null; } } }); }