如何从另一个类中的Java类调用变量

时间:2016-11-27 17:55:21

标签: java database user-interface inheritance actionlistener

如果我有一个带有预备语句的类,当用户按下按钮时如何调用它们。

class updateeButtonHandler implements ActionListener
{
    public void actionPerformed(ActionEvent e)
    {
        name = displayName.getText();
        price = bookPrice.getText();
        Queries update = new Queries();???????????????????
    }
}

不同班级的准备语句

public int update(String price, String name) throws SQLException {
        ps2.setString(1, name);
        ps2.setString(2, price);
        System.out.print("Update - ");
        return ps2.executeUpdate();
    }

1 个答案:

答案 0 :(得分:0)

创建一个对象并使用如下所示的参数调用update方法:

public void actionPerformed(ActionEvent e) {
        name = displayName.getText();
        price = bookPrice.getText();
        Queries update = new Queries(); 
        update.update(price, name);//invoke the method using the object
}