在另一个类中使用方法

时间:2015-11-06 06:49:10

标签: java

所以我将数据库作为学校项目的一部分,但我希望数据能够通过不同的按钮来提取,并且不希望必须拥有一个很长的代码每个按钮,所以我尝试在另一个类中创建一个方法,但我无法让它工作

public class DataGather extends HRDatabase {
public void getData(){
try{
        String ID = iDSearch.getText();
        String Query = ("Select * From employee where ID like " +  (ID)) ;
        PreparedStatement pst = con.prepareStatement(Query);
        ResultSet rs=pst.executeQuery();
        String rsID = rs.getString("ID");
        String rsName = rs.getString("name");
        String rsSurname  = rs.getString("surname");
        String rsAge = rs.getString("age");
        String rsHomephone = rs.getString("homephone");
        String rsMobile = rs.getString("mobile");
        String rsAddress = rs.getString("address");
        String rsSalary = rs.getString("salary");
        String rsGrade = rs.getString("grade");
        String rsCompanyCar = rs.getString("companycarID");
        String rsParkingArea = rs.getString("parkingarea");
        String rsCommission = rs.getString("commission");
        String rsSalesVolume = rs.getString("salesvolume");
        String rsSoftware = rs.getString("softwaresetID");
        nameTextField.setText(rsName);
        iDTextField.setText(rsID);
        surnameTextField.setText(rsSurname);
        ageTextField.setText(rsAge);
        contactNumberTextField.setText(rsHomephone);
        addressTextField.setText(rsAddress);
        salaryTextField.setText(rsSalary);
        gradeTextField.setText(rsGrade);

        }catch(Exception e)
    {
        JOptionPane.showMessageDialog(null, e);
    }
    }

以上是方法

btnEditEmployee.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            //getData()  
        }
    });

我尝试了一些方法,但没有任何效果,任何帮助都会受到赞赏

0 个答案:

没有答案