hibername 调用存储过程

JshxTaskDaoImpl
import java.sql.CallableStatement;
@Override
	public void callTaskManageProcedure() {
		List<Object> params = null;
		try {
			callProcedure1("{call TaskManager()}", params);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//this.callProcedure("{call TaskManager()}", null);
		//this.callProcedure("TaskManager", null, null);
	}
	
	public void callProcedure1(String procString,List<Object> params) throws Exception {
		java.sql.CallableStatement stmt = null;
		try {
			stmt = (CallableStatement) this.getSession().connection().prepareCall(procString);
			if (params != null){
			int idx = 1;
			for (Object obj : params) {
				if (obj != null) {
					stmt.setObject(idx, obj);
				} else {
					stmt.setNull(idx, Types.NULL);
				}
				idx++;
				}
			}
			stmt.execute();
		} catch (SQLException e) {
			e.printStackTrace();
			throw new Exception("调用存储过程的时候发生错误[sql = " + procString + "]", e);
		}
	}

你可能感兴趣的:(存储过程)