I want to fill my jcombobox from my database, but only the first record is filled and not all the others, it should be loaded as soon as the jframe form is opened
Here I initialize my method to fill the combobox
public class adm_pedidos extends javax.swing.JFrame {
/**
* Creates new form adm_pedidos
*/
Connection cn = null;
Statement stm = null;
PreparedStatement ps = null;
ResultSet rs = null;
String sql = null;
public adm_pedidos() {
initComponents();
mostrarpedidos();
llenar_combo_actividad();
llenar_combo_usuarios();
this.setLocationRelativeTo(null);
this.setResizable(false);
}
And this is the method:
private void llenar_combo_actividad() {
try {
sql="select distinct(codigo_actividad),descripcion from activida_gasto";
cn = accesodb.getConnection();
stm= cn.createStatement();
rs=stm.executeQuery(sql);
System.out.println(sql);
while(rs.next()){
cbxactividad.addItem(rs.getString(2));
}
}catch(Exception e){
JOptionPane.showMessageDialog(rootPane, e);
}
}
As you can see, there is a system.out.print.ln to see what the query is and I get it correct, that is, if I put it in the mysql, all the records come out. When I debug, it only enters once in the rs. next () and that's why it only registers the first one, but it's not because it only enters once, if it's supposed to be several records I hope your help thanks