public List<Course> searchCourse(String name) {
List<Course> list = null;
Course course = null;
PreparedStatement pstmt = null;
ResultSet rs = null,rs1 = null;
String sql = "select username,course_name from view_teacourse where username=? or course_name=? ";
try{
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, name);
pstmt.setString(2, name);
rs = pstmt.executeQuery();
while(next()){
String sql1 = "select * from courseinfo where course_name=?";
pstmt.setString(1, rs.getString("cousre_name"));
rs1 = pstmt.executeQuery();
while(rs1.next()){
course.setCourseid(rs.getInt("course_id"));
course.setCourseName(rs1.getString("course_name"));
course.setCourseScheme(rs.getString("course_scheme"));
course.setCourseBook(rs.getString("course_book"));
course.setCourseTerm(rs.getString("course_term"));
course.setIntroduction(rs.getString("introduction"));
course.setStartTime(rs.getTimestamp("start_time"));
course.setEndTime(rs.getTimestamp("end_time"));
course.setValidation(rs.getBoolean("validation"));
course.setCourseType(rs.getInt("coursetypeid"));
list.add(course);
}
}
}catch(Exception e){
e.printStackTrace();
}finally{
DBBase.releaseResultSet(rs1);
DBBase.releaseResultSet(rs);
DBBase.releaseStatement(pstmt);
DBBase.releaseConnection(conn);
}
return list;
}
的值rs.next()
越来越错误。它不能进入while循环。但是,如果我rs.wasNull()
这样写,我又弄错了。所以我很困惑。我可以在我的数据库中使用相同的 SQL 获得正确的结果。当它在java文件中时它不起作用!我找不到错在哪里!