Because the for cycle in Java is executed twice

0

It turns out that I have this function that contains this for cycle in Java that makes records of the rows in the JTable to the database

public void registrarResultado() {
       DefaultTableModel tbl_model = (DefaultTableModel) vista.tabla_estudiantes.getModel();
      String materia = vista.tabla_materia.getModel().getValueAt(vista.tabla_materia.getSelectedRow(), 0).toString();

        int rows = tbl_model.getRowCount(); // ESTO ES IGUAL A 3
        int columns = tbl_model.getColumnCount()-1; // ESTO ES IGUAL A 4

        for (int i = 0; i < rows; i++) {
            for (int j = 3; j < columns; j++) {
                String cedula = tbl_model.getValueAt(i, 0).toString();
                double ponderacion = Double.parseDouble(tbl_model.getValueAt(i, j).toString());
                String codigo_examen = tbl_model.getColumnName(j);
                modelo = new resultado(materia, cedula,  codigo_examen,  ponderacion); 
                modelo.registrarResultado();
            }
        }

    }

These are the data in the JTable

And these are the data that reach the BD

It stores the data correctly, however, it duplicates them because it executes the cycle for twice and I do not understand why, that is, when the first cycle of rows (rows) reaches 3 it makes a cut, because obviously it should break the execution of the cycle since it fulfilled the conditions, but then it is again executed from scratch again and executes everything inside again, but the strange thing is that it does it twice, and I do not understand why.

    
asked by Anthony Medina 21.11.2017 в 03:16
source

0 answers