[英]How do I call variables from a Java class in another Class
If I have a class with prepared statements, how do I call them when a user presses a button. 如果我有一个带有预处理语句的类,当用户按下按钮时如何调用它们。
class updateeButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
name = displayName.getText();
price = bookPrice.getText();
Queries update = new Queries();???????????????????
}
}
Prepared Statement in different class 在不同的班级准备声明
public int update(String price, String name) throws SQLException {
ps2.setString(1, name);
ps2.setString(2, price);
System.out.print("Update - ");
return ps2.executeUpdate();
}
Create an object and invoke the update method with parameters as shown below: 创建一个对象并使用如下所示的参数调用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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.