It is not sent to call java method, help!

0

Hello good morning to all, today I am trying a java method and the problem is that it is not sent to call, it is a hashMap this is the original code that was "hard code" and then changed dynamically by means of a SQL query within a method, this is the original "hard":

{
        this.correspondencia=new HashMap<String, String>();
        correspondencia.put("A","101");
        correspondencia.put("B","102");
        correspondencia.put("B1","102");
        correspondencia.put("B2","102");
        correspondencia.put("B3","102");
        correspondencia.put("B4","102");
        correspondencia.put("BPR","102");
        correspondencia.put("C","102");
        correspondencia.put("DF","102");
        correspondencia.put("EFA","102");
        correspondencia.put("EXF","102");
        correspondencia.put("GPF","102");
        correspondencia.put("MB","102");
        correspondencia.put("MFA","102");
        correspondencia.put("P","102");
        correspondencia.put("PPR","102");
        correspondencia.put("PV","102");
        correspondencia.put("TF","102");
        correspondencia.put("UHN","102");
        correspondencia.put("B","103");
        correspondencia.put("B-1","103");
        correspondencia.put("B-2","103");
        correspondencia.put("B-3","103");
        correspondencia.put("B-4","103");
        correspondencia.put("B-5","103");
        correspondencia.put("B-6","103");
        correspondencia.put("DM","103");
        correspondencia.put("E","103");
        correspondencia.put("E1","103");
        correspondencia.put("E2","103");
        correspondencia.put("EC","103");
        correspondencia.put("EXM","103");
        correspondencia.put("IF","103");
        correspondencia.put("TM","103");
        correspondencia.put("TM1","103");
        correspondencia.put("DNC","104");
        correspondencia.put("NC","104");
        correspondencia.put("NC1","104");
        correspondencia.put("NC2","104");
        correspondencia.put("NC3","104");
        correspondencia.put("NC4","104");
        correspondencia.put("NC5","104");
        correspondencia.put("NC6","104");
        correspondencia.put("NCC","104");
        correspondencia.put("TNC","104");
        correspondencia.put("TNC1","104");
        correspondencia.put("B","105");
        correspondencia.put("EX","105");
        correspondencia.put("F","107");
        correspondencia.put("GB","108");

    }


    private double calculaInversion(String nb_serie,List<VivVAACInversion> catalogoInversion) {
      //Aqui es donde se manda a llamar el map de arriba.'
        String clave=this.correspondencia.get(nb_serie);'
        double id=0;

        for (VivVAACInversion vivVAACInversion : catalogoInversion) {
            if(clave.equalsIgnoreCase(vivVAACInversion.getNombreClave())){
                id=vivVAACInversion.getIdInversion();
            }
        }

        return id;
    }

And this is the dynamic code that remained:

public static void correspondencia(){


        correspondencia=new HashMap<>();
        //Se reemplaza código duro por dinámico.
        ResultSet rs = null;
        Connection conn = null;
        try {
            if(conn !=null) {
                String sql = "SELECT\r\n" + 
                        "    tviv055_intiserie.nb_serie,\r\n" + 
                        "    tviv053_inversion.nb_clave\r\n" + 
                        "FROM\r\n" + 
                        "    ( tviv056_relserie\r\n" + 
                        "    INNER JOIN tviv055_intiserie ON tviv056_relserie.cd_serie = tviv055_intiserie.cd_serie )\r\n" + 
                        "    INNER JOIN tviv053_inversion ON tviv056_relserie.cd_inversion = tviv053_inversion.cd_inversion";
                Statement stmt0 = conn.createStatement();
                while (rs.next()) {
                    //Se llena el map con el resultado de la consulta.
                    correspondencia.put(rs.getString("NB_SERIE"), rs.getString("NB_CLAVE"));
                }
            }
        }catch(SQLException e) {
            System.out.println( "SQL exception: " + e.getMessage());  
        }

    }

    private double calculaInversion(String nb_serie,List<VivVAACInversion> catalogoInversion) {
        String clave=this.correspondencia.get(nb_serie);
        double id=0;

        for (VivVAACInversion vivVAACInversion : catalogoInversion) {
            if(clave.equalsIgnoreCase(vivVAACInversion.getNombreClave())){
                id=vivVAACInversion.getIdInversion();
            }
        }

        return id;
    }

Attach this image of some warnings that appear and send me a message of "Dead code":

I hope and you can offer me your help, in advance I send you a cordial greeting, and if you still need to attach it that is not understood with pleasure I will put it.

    
asked by JUAN JOSE BUSTAMANTE SOLIS 27.04.2018 в 18:36
source

2 answers

2

You have the following:

Connection conn = null;
try {
    if(conn !=null) {
    ...

Define conn as null and then say if it's not null I do ... .

But as conn is null that code will never be executed.

    
answered by 27.04.2018 в 19:26
0

Before the while you lack something like this:

rs = stmt0.executeQuery(sql);

That's why it indicated that the sql variable was unused.

Greetings.

David

    
answered by 27.04.2018 в 18:54