public class HandleEmp {
public ArrayList<E> selectEmp(String up) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/empsys", "root", "root");
Statement stm=connection.createStatement();
String sqlString="select * from users where 1=1";
if(!up.equals(""))
sqlString=sqlString+" and username like '%"+up+"%'";
ResultSet rs=stm.executeQuery(sqlString);
ArrayList<Emp> arrayList=new ArrayList<Emp>();
while(rs.next()) {
Emp e=new Emp();
e.setId(rs.getInt("id"));
e.setUsername(rs.getString("username"));
e.setPass(rs.getString("pass"));
arrayList.add(e);
}
return arrayList;
}catch(Exception e) {
e.printStackTrace();
return null;
}
}
}
上面是代码
我想问一下这 public ArrayList selectEmp(String up)为什么要用ArrayList呢