Obtain the value of a variable in another class?
I have a problem getting the variables to pass to another class, because
it keeps passing me a blank variable.
I want to get the value of id from the method search() and transfer it to
class foo inside the method total...
Class Boo :
//method inside of class boo
public void search(){
try{
String id = searchBox.getText();
String idNum="";
rs = stat.executeQuery("Select * from students where
idNum='"+id+"'");
while(rs.next()){
idNum = rs.getString("idNum");
}//while
Members members = new Members();
setVisible(false);
members.setIdVal(id);
}catch(Exception e){
System.out.println("Error: "+e);
}
}//search
Class Foo:
// methods inside Foo
public void total(){
System.out.println("Get: "+getIdVal());
try{
rs2 = stat2.executeQuery("SELECT * FROM paymentRecord where idNum
='"+getIdVal()+"';");
}catch(Exception e){
System.out.println("Total Error: "+e);
}//
}//total
public void setIdVal(String val){
this.val = val;
}//get the id
public String getIdVal(){
//System.out.println("Inputted ID:" + val);
return this.val;
}//get the id
No comments:
Post a Comment