Database and Java

0

I am trying to filter in a database from a combobox, for example if in the combobox you choose systems in the table you should show the data of only that area, I have this code:

String lugar=String.valueOf(combo.getSelectedItem());
ResultSet c=null;
try{
c=stat.executeQuery("select * from empleados where area= '"+lugar+"'");

}
catch(Exception e){
e.printStackTrace();
}

I have tried doing it from a textbox but it does not work, and I already probe in this way:

String lugar=String.valueOf(combo.getSelectedItem());

try{
stat.executeUpdate("select * from empleados where area= '"+lugar+"'");

}
catch(Exception e){
e.printStackTrace();
}
    
asked by Hector 07.04.2018 в 21:56
source

1 answer

0

You are only capturing the ResultSet, you have to go through it with a loop, there are several methods like getString​(int columnIndex) that allows you to obtain the ResultSet data, I recommend you go through this link where you will find the necessary documentation.

link

Example:

while(rs.next){
     System.out.println(rs.getString(1));
}

As output you will have the values of position one of your scheme ResultSet

    
answered by 16.07.2018 в 16:57