日期:2014-05-17 浏览次数:20809 次
public List<Student> SearchStudent(String studentNo, String name, int sex, int classes, String birthday) {
String sql = "SELECT a.* FROM AA_XQ a WHERE 1 = 1";
if(studentNo != "" && studentNo.length() != 0)
sql+=" and a.STUDENTNO = ?";
if(name != "" && name.length() != 0)
sql+=" and a.NAME = ?";
if(sex != 0)
sql+=" and a.SEX = ?";
if(classes != 0)
sql+=" and a.CLASSES = ?";
if(birthday != "" && birthday.length() != 0)
sql+=" and a.BIRTHDAY = ?";
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
ArrayList<Student> list = new ArrayList<Student>();
try {
conn = connection.getConnection();
ps = conn.prepareStatement(sql);
if(studentNo != "" && studentNo.length() != 0)
ps.setString(1, studentNo);
if(name != "" && name.length() != 0)
ps.setString(2, name);
if(sex != 0)
ps.setInt(3, sex);
if(classes != 0)
ps.setInt(4, classes);
if(birthday != "" && birthday.length() != 0)
ps.setString(5, birthday);
rs = ps.executeQuery();
while (rs.next()) {
Student s = new Student();
s.setStudentNo(rs.getString("studentNo"));
s.setName(rs.getString("name"));
s.setSex(rs.getInt("sex"));
s.setClasses(rs.getInt("classes"));
s.setBirthday(rs.getDate("birthday"));
s.setId(rs.getInt("id"));
list.add(s);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
connection.close(rs, ps, conn);
}
return list;
}