我在将变量传递给另一个类时遇到问题,因为它一直向我传递一个空白变量。
我想id
从方法中获取值search()
并将其转移到class foo
方法内部total
...
类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
类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