Is there any way that I don't use lots of IF statements?,right now it is according to Index of combo box items.

else if(e.getSource().equals(jcb1))
        {
            int selectedindex = jcb1.getSelectedIndex();
            String comb_string = (String)jcb1.getSelectedItem();            
            if(selectedindex==1)
            {
                try {

                //String sql_command ="select * , count(*) over (partition by 1) total_rows from Employer where Employername = ? ";             
                String sql_command ="select * from Employer where Employername = ? ";
                    PreparedStatement st=con.prepareStatement(sql_command);                 
                    st.setString(1,comb_string);
                    Result = st.executeQuery();
                    int test =0;
                    String Store="";
                    String Response ="";
                    test++;
                    if(Result.next())
                    {                       
                        String add1=Result.getString(3);
                        first.setText(add1);
                        String add2=Result.getString(28);
                        second.setText(add2);
                        String add3=Result.getString(4);
                        third.setText(add3);
                        String add4=Result.getString(6);
                        fourth.setText(add4);

                        if(test !=0)
                        {
                            /*Result.absolute(test);
                            DisplayData();*/
                            Response = "Number of Records that Matches :"+test+Store;
                            JOptionPane.showMessageDialog(null, Response);              
                        }
                        else
                        {
                            JOptionPane.showMessageDialog(null,"Could not be found");
                        }


                    }
                } catch (SQLException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }                   
            }           
        }   

You don't give a lot of context for this question, but it looks like you should be using a switch based on the selected index, and in that calling separate methods for each of the possible cases.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.