I'm trying to load previously stored data in a bd to a Java form
What I want to achieve is that by selecting a list from the combobox load all the corresponding data (name, age, phone)
My problem: When selecting a rut from the list, the other fields do not change, they remain with the values corresponding to the first rut shown
The data is well saved, since I have a file in which I show, update and delete
I insert my method:
private void cbrutcActionPerformed(java.awt.event.ActionEvent evt) {
try {
String rut = cbrutc.getSelectedItem().toString();
String sql = "SELECT * "
+ "FROM cliente "
+ "WHERE rut = '" + rut + "';";
Conex cn = new Conex();
ResultSet rs = cn.consulta();
while (rs.next()) {
String nm = rs.getString("nombre");
String ed = rs.getString("edad");
String tl = rs.getString("telefono");
tfnombrec.setText(nm);
tfedadc.setText(ed);
tftelefonoc.setText(tl);
tfmontoc.requestFocus();
}
} catch (Exception e) {
System.out.println(e);
}