public ArrayList findBulr(student s){
try {
Connection con = DBManager.getConncection();
Statement st = con.createStatement();
String c = "";
if (!s.getStuName().equals("")) {
c += " stuName like '%" + s.getStuName() + "%' AND ";
}
if (!s.getStuPhone().equals("")) {
c += "stuPhone like '%" + s.getStuPhone() + "%' AND ;";
}
if (!s.getStuAddress().equals("")) {
c += " stuAddress like '%" + s.getStuAddress() + "%' AND ";
}
String sql = "select *from student studentInfo where"+c;
sql += sql.substring(0, sql.length() - 4);
ResultSet rs = st.executeQuery(sql);
System.out.println(sql);
ArrayList list=new ArrayList();
while(rs.next()){
student a=new student();
a.setStuID(rs.getInt("stuID"));
a.setStuPhone(rs.getString("stuName"));
a.setStuSex(rs.getString("stuSex"));
a.setStuAge(rs.getInt("stuAge"));
a.setStuBirthday(rs.getString("stuBirthday"));
a.setStuAddress(rs.getString("stuAddress"));
a.setStuPhone(rs.getString("stuPhone"));
a.setClassName(rs.getString("className"));
list.add(a);
}
rs.close();
st.close();
con.close();
return list;
} catch (SQLException ex) {
ex.printStackTrace();
return null;
}
帮忙看看sql语句对不,我写的模糊查找!