I am using NetBeans

i have a 'Search by employee id' button .

I want when user click this button a dialogue box appear which take employee_id as input from user .
then that input be used for fethcing data from the database ( desired table in DB has primary key emp_id ).

How can i do this ?
I just want to use the Input (as String) given by user in dialogue box ..

Please Help!

Thanx In Advance..

If the data you want is contained in varaibles in the dialog box class, you need to add methods to that class that you can call to get the data.

Can you post the code you are having problems with.

thats whatn i want -- The Code ---
I dont know what to code for getting user input through dialogue box when a button is pressed.

Can you please Help with the code.

Okay here is the code for the actionPerformed event of the get employee detail button

 private void search_empDetails_by_empId(java.awt.event.ActionEvent evt) {

      try {
     String empId = JOptionPane.showInputDialog("Enter Employee ID :");

    Statement stmt=con.createStatement();
    String sql1 = "Select * from emp where emp_id = '" + (empId) + "'";
    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");
        String dob = rs.getString("dob");
        String do_join = rs.getString("dojoin");
        String mobile = rs.getString("mob");
        String electmail = rs.getString("email");
        String ageyr = rs.getString("age");
        String sexmf = rs.getString("sex");
        String addrs = rs.getString("address");

        String proj_handled = rs.getString("project_handled");
        String curr_proj = rs.getString("current_project");
        String exp = rs.getString("experience");
        String skill = rs.getString("skills");

        String train_done = rs.getString("training_done");
        String curr_train = rs.getString("current_training");
        String skill_rmk = rs.getString("skill_remark");

        String sal_block = rs.getString("salary_block");
        String ann_income = rs.getString("annual_income");
        String facility = rs.getString("facilities");
        String insure = rs.getString("insurance"); 
// setting data in tab Employee details
jTextField27.setText(""+ empid);
jTextField28.setText(""+ f_name);
jTextField29.setText(""+ l_name);
jTextField30.setText(""+ qual);
jTextField31.setText(""+ dept);
jTextField32.setText(""+ dob);
jTextField33.setText(""+ do_join);
jTextField34.setText(""+ mobile);
jTextField35.setText(""+ electmail);
jTextField36.setText(""+ ageyr);
jTextField37.setText(""+ sexmf);
jTextField38.setText(""+ addrs);

// Setting data in tab Skill Report
jTextField6.setText(""+ proj_handled);
jTextField7.setText(""+ curr_proj);
jTextField8.setText(""+ exp);
jTextField12.setText(""+ skill);

// Setting data in tab Training Report
jTextField16.setText(""+ train_done);
jTextField18.setText(""+ curr_train);
jTextField19.setText(""+ skill_rmk);

// Setting data in tab compensation Report
jTextField23.setText(""+ sal_block);
jTextField24.setText(""+ ann_income);
jTextField25.setText(""+ facility);
jTextField26.setText(""+ insure);

// Skill Report
jTextField1.setText(""+ empid );
jTextField2.setText(""+ f_name);
jTextField3.setText(""+ l_name);
jTextField4.setText(""+ qual);
jTextField5.setText(""+ dept);

//Training Report
jTextField9.setText(""+ empid);
jTextField11.setText(""+ f_name);
jTextField13.setText(""+ l_name);
jTextField14.setText(""+ qual);
jTextField15.setText(""+ dept);

//Compensation Report
jTextField17.setText(""+ empid);
jTextField20.setText(""+ f_name);
jTextField21.setText(""+ l_name);
jTextField22.setText(""+ dept);

   // making new employee password field noneditable and invisible
        jTextField39.setEditable(false);  // new employee password field.
        jTextField39.setVisible(false);
        jLabel43.setVisible(false);
    }
}
catch(Exception e) {
    JOptionPane.showMessageDialog(this, e.getMessage());
}

I dont know where the problem is??
what i Run the program and click 'get emp_detil ' button a input dialog appear and ask for input.
when input and given and Ok is pressed it just disappears and nothing happens..

Please Help.
Thanx in advace..

Edited 4 Years Ago by pyTony: Indent or ~~~ for Markdown code blocks, please

and i have already given

try{
        String un="root";
        String pass="soft";
        String url="jdbc:mysql://localhost/hrms";
        Class.forName("com.mysql.jdbc.Driver");
        con=DriverManager.getConnection(url,un,pass);



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

    // in the constructor of the class

Edited 4 Years Ago by pyTony: removed single ` to fix code block

This question has already been answered. Start a new discussion instead.