public static ArrayList<Machine> fillMachineMagCylinders(ArrayList<Machine> machines, ArrayList<MagnetCylinder> magnetCylinders) throws SQLException {

        Statement stm = conn.createStatement();
        ResultSet rs = stm.executeQuery("select m.name_machine, mc.teeth from Machine m " +
                "INNER JOIN Machine_MagnetCylinder mmc ON m.id_machine = mmc.id_machine " +
                "INNER JOIN MagnetCylinder mc ON mmc.id_magnet_cylinder = mc.id_magnet_cylinder ORDER BY mc.teeth");

        while (rs.next()) {
            for (int i = 0; i < machines.size(); i++) {
                if (machines.get(i).getName().equals(rs.getString("name_machine"))) {
                    for (int j = 0; j < magnetCylinders.size(); j++) {
                        if (magnetCylinders.get(j).getTeeth() == rs.getInt("teeth")) {
                            machines.get(i).addCylinder(magnetCylinders.get(j));
                            break;
                        }
                    }
                    break;
                }
            }
        }

        stm.close();
        rs.close();
        return machines;
    }