我花了一整天时间寻找这个,据我检查,我总是坚持使用一个空的ArrayList。我也尝试只显示我找到的第一条记录,然后我得到了null。应该插入到ArrayList中的只是课程,所以Strings。
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;
}
答案 0 :(得分:0)
您将数据插入数组列表的位置?你需要这一行:
s = new String(rst.getString(“title”));
result.add(s)