我整天都在寻找这个,据我检查,我总是坚持使用一个空的 ArrayList。我还尝试只显示我找到的第一条记录,但我得到了空值。应该插入 ArrayList 的只是课程,所以是字符串。
public String getProfessorCourses(){
................
//get the id related of the name
String s = null;
String sqlQuery = "SELECT courses.title FROM courses INNER JOIN professors_courses ON professors_courses.course_id = course.course_id WHERE prof_id = '"+1+"'";
ArrayList<String> result = new ArrayList<String>();
try {
rst = stmt.executeQuery(sqlQuery);
} catch (SQLException e1) {
e1.printStackTrace();
}
try {
//titles are not inserted
while(rst.next()){
//s = new String(rst.getString(1));
//s = rst.getString(1);
s = new String(rst.getString("title"));
}
} catch (SQLException e) {
e.printStackTrace();
}
.........................
return s;
}