Call Oracle data to a NetBeans Table [closed]

0

I would like help on this topic, because I really do not know how to do it.

My question is, I have a form in my NetBeans and when I click on the button I should pull the data that I have in my Oracle and show them in the table I have there ... how could I do it ?, please help.

And another query would be, apart from pulling the data from my oracle and showing them in the table, how could I pull a data ... but from that oracle data show a data in a Jlabel and the rest if it goes to the table?

I need your help, please

    
asked by Bloom 29.09.2018 в 19:30
source

1 answer

0

You just have to create a method in your form where you fill in your table executing a query where you can query the table you have in your DB and empty that query data in your form table

I'll show you an example method

   void mostrarDatos(){

    DefaultTableModel model = new DefaultTableModel();
    model.addColumn("ID");
    model.addColumn("Nombre");
    model.addColumn("Edad");
    model.addColumn("Sexo");

    tabla.setModel(model);
    String sql = "SELECT * FROM tablaPersona";

    String datos[] = new String[5];
    try {
        Statement st = cn.createStatement();
        ResultSet rs = st.executeQuery(sql);//Aqui ejecuta la consulta
        while(rs.next()){//Se hace el llenado de la tabla con los datos que se obtienen  de la consulta
            datos[0] = rs.getString(1);
            datos[1] = rs.getString(2);
            datos[2] = rs.getString(3);
            datos[3] = rs.getString(4);
            model.addRow(datos);
        }
        tabla.setModel(model);

        if(tabla.getModel().getRowCount() == 0){
            JOptionPane.showMessageDialog(null, "NO SE ENCONTRO NINGUNA COINCIDENCIA","AVISO",JOptionPane.INFORMATION_MESSAGE);
            mostrarDatos("");
        }
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null,"Error en la consulta..." + ex.getMessage());
        Logger.getLogger(frm_users.class.getName()).log(Level.SEVERE, null, ex);
    }

}
    
answered by 29.09.2018 / 20:16
source