Priyanjan
how to know which jList is selected and according to that fetch the value
0 Answer(s)      3 years and 4 months ago
Posted in : Swing AWT

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

Advertisement
View Answers









Related Tutorials/Questions & Answers:
how to know which jList is selected and according to that fetch the value
how to know which jList is selected and according to that fetch the value ... 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
Display JList value selected from the JOptionPane
Display JList value selected from the JOptionPane In this section, we are going to select the particular value from the JOptionPane combobox and displayed that value in the JList. For this purpose, we have created a button and JList
Advertisements
fetch database value to text box based on selected value my code given below pls correct my code
fetch database value to text box based on selected value my code given below...="destination" onchange="getPrice()"> <html:option value="0">...;<input type="text" value =" " property= "amount" id='pricecheck'/> <
fetch database value to text box based on selected value my code given below pls correct my code
fetch database value to text box based on selected value my code given below...="destination" onchange="getPrice()"> <html:option value="0">...;<input type="text" value =" " property= "amount" id='pricecheck'/>
How to know the selected row from table - JSP-Interview Questions
How to know the selected row from table  hi Every one....i am... place one table data as hyperlink. now the problem here is how can i know the selected row in that table.  Hi Friend, Please clarify your
jList
jList  how to remove value from jlist after clicking on that value
How to pass the value of Selected Value of combo box into sql ??
How to pass the value of Selected Value of combo box into sql ??  My SQL Database Name is MHS, user=root, password=admin,table name is sub_comb... submit i want to display other field. how to get it?? plz help me
how to display textbox value based on selected option value?
how to display textbox value based on selected option value?  Hi,I... on first value I finished above code. ID: xx Name:xx xx is baesd on second and first value. But it is that l can't do that. now, l post my code
how to display data from database according to entered value in search field
how to display data from database according to entered value in search... please. i don't know which line i have to add or change my code. thank you...;/b></td> <td>: <input type="text" name="bmi_value" id="BMI
jList
jList  how to get the jlist values into jtextfield after clicking on the value?? plzz help   Here is an example that shows the selected value from the jlist to textfield. import java.awt.*; import javax.swing.*; import
jList
jList  how to add checkbox for every value in jlist having values populated from ms access database using java netbeans
how to update combobx's selected value to database with respect toselected multiple checkboxes
how to update combobx's selected value to database with respect toselected multiple checkboxes   suppose this if form1.jsp in which i am going... values which is selected from form1.jsp String languages=""; String box
change color according to the database value
change color according to the database value  any one know how to get values from database ( 1 or 0 ) and according to that change the color ( red or green) of given list
Jlist
JcomboBox to a Jlist  How to transfer a data from a JcomboBox to a Jlist ? Each time I select 1 item from a JComboBox, it will display in a JList
SQL fetch value
SQL fetch value  how to get ( 15 march 2011) and (15/03/2011) output using SQL   Use the following queries to get the data from database in the given format. For (15 march 2011) format: SELECT DATE_FORMAT(dob, '%d %M
JList
JList  pls tell me about the concept the JList in corejava? and tell me a suitable example
Java swing: get selected value from combobox
Java swing: get selected value from combobox In this tutorial, you will learn how to get selected value from combobox. The combobox provides the list... imposed an actionlistener on the combobox in order to get the selected value from
. Display JavaScript dropdown selected value
. Display JavaScript dropdown selected value  How to get the selected...("dropdown").value; alert("You selected : " + dropdownValue); } <... dropdownValue we are storing the selected value by using
how to fetch values from .properties to a html file
how to fetch values from .properties to a html file  I have a .properties file with some key value pairs in it. I need to fetch the values from this .properties file into a html file.Please let me know how to do
Java JComboBox Get Selected Item Value
how to get the selected item value form JComboBox. javax.swing.JComboBox.... In this tutorial we are discussing about how to store the selected item value... example into which I shall get the combo box selected item value and stored
how to fetch data from servlet ????
how to fetch data from servlet ????  how to fetch data from servlet
jlist in swings
jlist in swings  how to populate jlist with all the data retrieved from the ms access database?plzz help
Struts2 and Hibernate Fetch Data Base Value
me what should i do for fetch the database value and shown on jsp page...") public > List<AdminProvideLeave>fetch1()// for > fetch the value from...Struts2 and Hibernate Fetch Data Base Value  Hello Sir, I am
Struts2 and Hibernate Fetch Data Base Value
me what should i do for fetch the database value and shown on jsp page...") public > List<AdminProvideLeave>fetch1()// for > fetch the value from...Struts2 and Hibernate Fetch Data Base Value  Hello Sir, I am
Populate listbox according to selection value from another selectbox
Populate listbox according to selection value from another selectbox  hi... I am developing my webproject in which i have 3 campus and each campus... listbox from database but campus list box will removes selected value.. please help
Dynamically display values in dropdown box and then show the selected values as selected by the user which is already stored in the DB
as selected by the user which is already stored in the DB  The below... this code it is adding one more value to the dropdown box and showing as selected.... Can you please help me to show more than one value as selected pulling those
Dynamically display values in dropdown box and then show the selected values as selected by the user which is already stored in the DB
Dynamically display values in dropdown box and then show the selected values as selected by the user which is already stored in the DB   Hello, This is for Updating. I had two SQL queries one for only selected values
Jlist and JTextfield
Jlist and JTextfield  How can we filter values from jlist by adding only a single letter in jtextfield such that when letter S is pressed in jtextfield then jlist should diplay all the values starting from letter S.I am using
how to fetch image from mysql using jsp
how to fetch image from mysql using jsp  how to fetch image from mysql using jsp
How to change the value of a variable which is set in jsp (by jstl method) by calling the function from js?
How to change the value of a variable which is set in jsp (by jstl method) by calling the function from js?  How to change the value of a variable... the value of 'name1' as "Edit User" when calling the editUser function which
I am not able to display the selected value of my combobox
I am not able to display the selected value of my combobox   <?php echo "<select name=\"hello\">\n"; echo "<option value=\"NULL\">...; $select='<select size=1 name="unitcode">'; while($arrayRow = mysql_fetch