2016-11-27 17 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

またあなたがコンストラクタまたはパスでクラスをインスタンス化することができより多くのオブジェクト指向になるようにメソッドの内部に作成するのではなく、コンストラクタに渡します。 –

+0

どうすればいいですか?返品されたディスプレイはどのように評価されましたか?ありがとう – joe

+0

アドバイスお願いします – joe

関連する問題