我希望能够将任何对象传递给searchO
方法,例如td1.searchO("akash")
or td1.searchO(1)
。它应该接受所有对象,因为对象类是所有对象的超类。
我该怎么做?
public boolean searchO(String o ) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException{
Statement st=null;
Connection con=test1.getConnection();
st=con.createStatement();
ResultSet rs=st.executeQuery("select * from `student` where `fname` = '" + o + "' ;");
//System.out.println("full name is "+rs.getString("lname")+" "+rs.getString("fname"));
if(rs.next()==true){
System.out.println("full name is "+rs.getString("lname")+" "+rs.getString("fname"));
return true;
}
else{
return false;
}
}