如何使用MyBatis将Oracle Procedure设置为Dto

时间:2018-07-30 19:17:06

标签: oracle mybatis

如何获取在oracle中执行的存储过程的以下属性,我需要使用spring获取mybatis xml中的游标,p_message,p_error_id ????

create or replace PACKAGE BODY PKG
AS
    PROCEDURE GET_TRACKING(fecha in varchar2, registros in number, p_mensaje out varchar2, p_error_id out number, p_list out SYS_REFCURSOR) is
    BEGIN
         BEGIN
             OPEN p_list FOR
             SELECT * FROM TRACKING;

             p_error_id := 1;
             p_mensaje  := 'OK';
         EXCEPTION
             when others then
                  p_error_id := -1;
                  p_mensaje  := substr(sqlerrm, 1, 100);

         END;
    END;
END;

在Java jdbc中,这是代码:

public int insertProcess(String processName, String processType, Response response) {
        Connection conn = null;
        CallableStatement stmt = null;
        try {
            Utils.loguea("Parametros de salida insertProcess processName  = " + processName + " processType = " + processType, "info");
            String statement = null;
            StringBuilder qryBuffer = new StringBuilder();
            qryBuffer.append("BEGIN ");
            qryBuffer.append(this.schema);
            qryBuffer.append(".GET_TRACKING(?, ?, ?, ?, ?); END;");

            statement = qryBuffer.toString();

            conn = this.dataSourceConector.getDataSource().getConnection();
            stmt = conn.prepareCall(statement);
            stmt.setString(1, processName);
            stmt.setString(2, processType);
            stmt.registerOutParameter(3, OracleTypes.INTEGER);
            stmt.registerOutParameter(4, OracleTypes.INTEGER);
            stmt.registerOutParameter(5, OracleTypes.VARCHAR);
            stmt.execute();
            int process_id = ((OracleCallableStatement)stmt).getInt(3);
            int error_id = ((OracleCallableStatement)stmt).getInt(4);
            String mensaje = ((OracleCallableStatement)stmt).getString(5);
            if (response != null) {
                response.setErrorID(error_id);
                response.setMensaje(mensaje);
            }

            Utils.loguea("Parametros de salida insertProcess error_id  = " + error_id + " mensaje = " + mensaje, "info");
            return process_id;
        } catch(Exception ex) {
            Utils.logueaException("Error en método insertProcess ", ex);
            if (response != null) {
                response.setErrorID(-1);
                response.setMensaje(ex.getMessage());
            }
            return -1;
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException ex) {
                    Utils.logueaException("Error al cerrar CallableStatement en método insertProcess", ex);
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException ex) {
                    Utils.logueaException("Error al cerrar Connection en método insertProcess", ex);
                }
            }
        }
    }

在Java代码中是这样的,但是在mybatis中,我需要帮助来获取p_error_id,p_message和光标,请帮助我。

0 个答案:

没有答案