Insert Strings from resultset into ArrayList

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sunsolaris2000
    New Member
    • Jan 2012
    • 20

    Insert Strings from resultset into ArrayList

    I've spend all day looking for this and as far as I checked I always stick with an empty ArrayList. I also tried to display just the first record I find and I got null.What should be inserted into ArrayList are only courses, so Strings.

    Code:
    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;
          }
  • sunsolaris2000
    New Member
    • Jan 2012
    • 20

    #2
    solved

    SOLVED

    I know wherethe problem was

    Comment

    Working...