Fill data with a ComboBox from MySQL

0

I am trying to make the information load when the first option is selected a project that was stored in a database and that at the time of selecting a project the respective information below is selected depending on the previously stored information and to be able to change a value for example the class, if when saving it the first time was erroneously, load the project and modify the class to save it again

First you save the information:

And then that information can be loaded for modification:

These are the methods I'm using:

public void guardar() {
    Conexion cn = new Conexion();
    Connection conn = cn.Conectar();
    ResultSet rs;

    try {
        String sql = "INSERT INTO nomejemplo "
            + "(idProyecto, nomProyecto, clase) values"
            + "(?,?,?)";
        PreparedStatement pst = conn.prepareStatement(sql);

        String nom = txtNombre.getText();
        pst.setString(2, nom);

        String n = (String) itemNumero.getSelectedItem();
        pst.setString(1, n);

        String c = (String) itemClase.getSelectedItem();
        pst.setString(3, c);

        pst.execute();

    } catch (SQLException ex) {
        System.out.println(ex.getMessage());
    }
}

private void getClase() throws SQLException {
    //Para cargar los materiales de las tuberias
    Conexion cn = new Conexion();
    Connection conn = cn.Conectar();
    ResultSet rs;
    String sql = "SELECT * FROM clase";
    PreparedStatement sqls = conn.prepareStatement(sql);
    rs = sqls.executeQuery();

    while (rs.next()) {
        CClase id = new CClase();
        id.setNombre(rs.getString("nom_clase"));
        itemClase.addItem(id.toString());
    }
}

private void getiD() throws SQLException {
    //Para cargar los materiales de las tuberias
    Conexion cn = new Conexion();
    Connection conn = cn.Conectar();
    ResultSet rs;
    String sql = "SELECT * FROM ejemplonumeros";
    PreparedStatement sqls = conn.prepareStatement(sql);
    rs = sqls.executeQuery();

    while (rs.next()) {
        CClase id = new CClase();
        id.setNombre(rs.getString("idNumero"));
        itemNumero.addItem(id.toString());
    }
}

private void getNombreP() throws SQLException {
    //Para cargar los materiales de las tuberias
    Conexion cn = new Conexion();
    Connection conn = cn.Conectar();
    ResultSet rs;
    String sql = "SELECT * FROM nomejemplo";
    PreparedStatement sqls = conn.prepareStatement(sql);
    rs = sqls.executeQuery();

    while (rs.next()) {
        getNombre id = new getNombre();
        id.setNombre(rs.getString("nomProyecto"));
        itemCargarProyecto.addItem(id.toString());
    }
}
    
asked by Arcade Ghost 27.10.2018 в 07:00
source

0 answers