Results 1 to 11 of 11
  1. #1
    drgnfire25 is offline Member
    Join Date
    Jan 2011
    Posts
    24
    Rep Power
    0

    Default how would I display this

    I created this and cant figure out how to display the return value, if anyone knows please help me out.

    Java Code:
       public List< graduate > getAllPeople()
       {
          List< graduate > results = null;
          ResultSet resultSet = null;
    
          try
          {
             // executeQuery returns ResultSet containing matching entries
             resultSet = selectAllPeople.executeQuery();
             results = new ArrayList< graduate >();
    
             while ( resultSet.next() )
             {
                results.add( new graduate(resultSet.getInt("studentID"),
                                               resultSet.getString("firstName"),
                                               resultSet.getString("lastName"),
                                               resultSet.getFloat("gpa"),
                                               resultSet.getString("Status"),
                                               resultSet.getString("mentor"),
                                               resultSet.getString("thesisTitle"),
                                               resultSet.getString("thesisAdvisor")));
    
             } // end while
          } // end try
          catch ( SQLException sqlException )
          {
             sqlException.printStackTrace();
          } // end catch
          finally
          {
             try
             {
                resultSet.close();
             } // end try
             catch ( SQLException sqlException )
             {
                sqlException.printStackTrace();
                close();
             } // end catch
          } // end finally
    
          return results;
       }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,788
    Rep Power
    7

    Default

    You cannot display a List. What you need to do is iterate over the List and display each item.

  3. #3
    drgnfire25 is offline Member
    Join Date
    Jan 2011
    Posts
    24
    Rep Power
    0

    Default

    so how would I do that from another class? I tried this but it says I cannot be referenced from a static context??

    Java Code:
            List results = studentQueries.getAllPeople();
                  Iterator<results> itr = results.iterator();
                    while (itr.hasNext()) {
                      results element = itr.next();
                      stuData.append(element + "\n ");

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,788
    Rep Power
    7

    Default

    In what class is the getAllPeople method?

    Is studentQueries a variable of that class?

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,788
    Rep Power
    7

    Default

    By the way, it helps if you copy and paste the EXACT error message. Usually it contains vital information that gets omitted when people paraphrase.

  6. #6
    drgnfire25 is offline Member
    Join Date
    Jan 2011
    Posts
    24
    Rep Power
    0

    Default

    studentQueries is the class that contains the method getAllPeople... the above code is in StudentView class

  7. #7
    drgnfire25 is offline Member
    Join Date
    Jan 2011
    Posts
    24
    Rep Power
    0

    Default

    exact error "non-static method getAllPeople() cannot be referenced from a static context"

  8. #8
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,788
    Rep Power
    7

    Default

    Wow, your compiler must hate you. Whenever I get error messages they look more like this
    Java Code:
    est.java:4: cannot find symbol
    symbol  : method doStuff()
    location: class Xfoo
            f.doStuff();
             ^
    1 error
    My compiler provides lots more information than yours.

  9. #9
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,788
    Rep Power
    7

    Default

    Quote Originally Posted by drgnfire25 View Post
    studentQueries is the class that contains the method getAllPeople... the above code is in StudentView class
    Since getAllPeople method is not static that means you cannot call it on the class. You must call it on an instance of the class. eg do you do this and expect the output to be 'h'?
    Java Code:
    String s = "hello";
    System.out.println(String.charAt(0));

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by drgnfire25 View Post
    exact error "non-static method getAllPeople() cannot be referenced from a static context"
    What junky is humorously telling you is that this is not the complete error message, and that if you supply more complete information, you'll likely get better help.

  11. #11
    drgnfire25 is offline Member
    Join Date
    Jan 2011
    Posts
    24
    Rep Power
    0

Similar Threads

  1. Replies: 1
    Last Post: 12-01-2010, 06:35 PM
  2. Display on top
    By karq in forum New To Java
    Replies: 12
    Last Post: 07-23-2010, 04:59 PM
  3. Replies: 1
    Last Post: 05-31-2010, 08:46 AM
  4. Replies: 8
    Last Post: 12-29-2008, 07:12 AM
  5. Replies: 0
    Last Post: 06-28-2008, 09:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •