Calling db package with return function and out parameters

    public HashMap getVchnofromDbPkg(String compcode, String unitcode, String finyrcode, String vchcode, Long vchid,String cbsubtype) {


        System.out.println("Vchno from pkg");
        CallableStatement sqlProcStmt2 = null;
        String sqlproc2 = "{? = call Fa_vchno_pkg.Get_Fa_VchNo(?,?,?,?,?,?,?)}";
//Fa_vchno_pkg. Get_Fa_VchNo(pCompCode varchar2, pUnitCode varchar2, pFinyrCode varchar2, pVchCode varchar2, pVchId number,
//     pCbSubType varchar2, pVchPrefix_o out varchar2)
        sqlProcStmt2 = this.getDBTransaction().createCallableStatement(sqlproc2, 0);
        String v_dt1 = null;
        HashMap<String, Object> hm = new HashMap<String, Object>();

        try {

            sqlProcStmt2.registerOutParameter(1, Types.VARCHAR);
            sqlProcStmt2.setString(2, compcode);
            sqlProcStmt2.setString(3, unitcode);
            sqlProcStmt2.setString(4, finyrcode);
            sqlProcStmt2.setString(5, vchcode);
            sqlProcStmt2.setLong(6, vchid);
            sqlProcStmt2.setString(7, cbsubtype);
            sqlProcStmt2.registerOutParameter(8, java.sql.Types.VARCHAR);
            sqlProcStmt2.execute();

            String v_ret_val = sqlProcStmt2.getString(1);
            v_dt1 = sqlProcStmt2.getString(8);
            hm.put("VchPrefix", v_dt1);
            hm.put("VchNo", v_ret_val);

            System.out.println("v_ret_val " + v_ret_val);


        } catch (SQLException e) {

            System.out.println(e.getMessage());
        } finally {
            try {
                if (sqlProcStmt2 != null && !sqlProcStmt2.isClosed())
                    sqlProcStmt2.close();
            } catch (Exception e) {
                e.printStackTrace();

            }

        }
        return hm;
    }

Comments