
Hi. I am Using netBeans..
I have 4 JLists (i.e jList1 , jList2, jList3 , jList4) in 4 different tabs in frame.
Each List has the value of employee_id from database (i successfully did it already) there are many field in tabs ( i.e rows of databse with employee id as primary key)
How to know which jList is selected so that i get the value of employee_id from the correct jList (i.e which is selected) to fetch data from database using selected employee id from selected jList with a common handler
A part of my program is
private void get_empid_detail(java.awt.event.MouseEvent evt) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con= (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/hrms","root","soft");
Statement stmt=con.createStatement();
boolean list1notSelected = jList1.isSelectionEmpty(); // caution or error whatever-> list1notSelected not in use
boolean list2notSelected = jList2.isSelectionEmpty(); // same for list2notSelected
boolean list3notSelected = jList3.isSelectionEmpty(); //same for list3notSelected
boolean list4notSelected = jList4.isSelectionEmpty(); // same for list4notSelected
String id;
if ( list1notSelected = false){
id = (String) jList1.getSelectedValue(); // caution or error whetever
}
else if(list2notSelected = false){ // every id in loop is not in use
id = (String) jList2.getSelectedValue();
}
else if(list3notSelected = false){
id = (String) jList3.getSelectedValue();
}
else if(list4notSelected = false){
id = (String) jList3.getSelectedValue();
}
String sql1 = "Select * from emp where emp_id = '" + (id) + "'"; //error -> variable id might not have been initised
ResultSet rs = stmt.executeQuery(sql1);
while (rs.next())
{
String empid = rs.getString("emp_id");
String f_name = rs.getString("first_name");
String l_name = rs.getString("last_name");
String qual = rs.getString("qualification");
String dept = rs.getString("department");
jTextField27.setText(""+ empid);
jTextField28.setText(""+ f_name);
jTextField29.setText(""+ l_name);
jTextField30.setText(""+ qual);
jTextField31.setText(""+ dept);
}
}
catch(Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
}
Please Help . I have to submitt my project on monday and this is the only bug remaining.. Please.. Every part of software is working properly except this problem.
THANK YOU IN ADVANCE
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.