2012-07-27 56 views
-1

我已经花了一整天找这一点,据我检查我总是一个空的ArrayList坚持。我也尝试显示我找到的第一个记录,并且我得到了空值。应该插入到ArrayList中的只有课程,所以Strings。插入到的resultSet 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; 
     } 

回答

0

你在哪里插入数据到数组列表中?您需要此行之后:

S =新的String(rst.getString( “标题”));

result.add(s)