By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,646 Members | 1,444 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,646 IT Pros & Developers. It's quick & easy.

Insert Strings from resultset into ArrayList

sunsolaris2000
P: 20
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.

Expand|Select|Wrap|Line Numbers
  1. public String getProfessorCourses(){
  2.        ................       
  3.        //get the id related of the name
  4.    String s = null;
  5.    String sqlQuery = "SELECT courses.title FROM courses INNER JOIN professors_courses ON professors_courses.course_id = course.course_id WHERE prof_id = '"+1+"'";
  6.  
  7.        ArrayList<String> result = new ArrayList<String>();
  8.  
  9.        try {
  10.          rst = stmt.executeQuery(sqlQuery);
  11.         } catch (SQLException e1) {
  12.             e1.printStackTrace();
  13.         }
  14.  
  15.        try {
  16.            //titles are not inserted
  17.             while(rst.next()){
  18.               //s = new String(rst.getString(1));
  19.               //s = rst.getString(1);
  20.                           s = new String(rst.getString("title"));    
  21.                 }
  22.         } catch (SQLException e) {
  23.             e.printStackTrace();
  24.         }
  25.        .........................   
  26.        return s;
  27.       }
Jul 27 '12 #1

✓ answered by sunsolaris2000

SOLVED

I know wherethe problem was

Share this Question
Share on Google+
1 Reply


sunsolaris2000
P: 20
SOLVED

I know wherethe problem was
Aug 1 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.