2016-11-27 113 views
1

如果我有一个准备好语句的类,当用户按下按钮时如何调用它们。如何在另一个类中调用Java类的变量

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(); 
    } 

回答

0

预处理语句创建一个对象,并调用与参数的更新方法如下所示:

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 
} 
+0

除了可以实例化类在construtor或通而不是在方法内部创建更多的面向对象。 –

+0

你会怎么做?如何显示返回价值。谢谢 – joe

+0

请任何意见 – joe

相关问题