I am developing a small application that fills me with a JComboBox based on a ResultSet. But I can not get it to show me a JTable with the results of a select *. To fill the JTable, I am using a mouse event so that when I select the table the JTable with the results will automatically appear. This would be the window:
If I now select a table from the clinical BD, the JTable with the results should appear in the panel below. attached source of my MouseListener and method fullTable:
Full methodTable:
public void llenarTablaResultados() throws ClassNotFoundException, SQLException{
modelo = new DefaultTableModel();
jtTablaResultados = new JTable();
jpTabla.add(jtTablaResultados);
Object bdSeleccionada = jcBD.getSelectedItem();
Object tablaSeleccionada = jcTablas.getSelectedItem();
MySQL.conecta("jdbc:mysql://localhost:3306/" + bdSeleccionada , "root", "1234");
MySQL.ejecutaConsulta("select * from " + tablaSeleccionada);
ResultSet rs = MySQL.getRs();
String[] cabecera = MySQL.getCabecera(rs);
Object[][] datos;
datos = MySQL.getDatos(rs);
modelo = new DefaultTableModel(datos, cabecera);
jtTablaResultados.setModel(modelo);
scrollpane = new JScrollPane(jtTablaResultados,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollpane.add(jtTablaResultados);
scrollpane.setBounds(90, 50, 700, 300);
scrollpane.setVisible(true);
jtTablaResultados.setVisible(true);
jtTablaResultados.setBounds(90, 50, 700, 300);
}
MouseListener
@Override
public void mouseClicked(MouseEvent e) {
jcTablas.removeAllItems();
Object tablaSeleccionada = jcTablas.getSelectedItem();
try {
llenarComboTablas();
if(jcTablas.getSelectedItem() == tablaSeleccionada){
llenarTablaResultados();
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error en la consulta");
} catch (ClassNotFoundException ex) {
JOptionPane.showMessageDialog(null, "No se encuentra la clase");
}
}
@Override
public void mousePressed(MouseEvent e) {}
@Override
public void mouseReleased(MouseEvent e) {}
@Override
public void mouseEntered(MouseEvent e) {}
@Override
public void mouseExited(MouseEvent e) {}