• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java JDBC jtable only displaying one record

 
Dene Lamprecht
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hallo

I am trying to display data from my ms SQL 2000 database in a jtable, the problem is that it only displays one record, though I know there should be 21 records. I think the problem has to do with the while (rs.next())??? but I just cant seem to fix it. Please help me out



thank you in advance
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
with the rows[i] loop inside the while(rs.next()) loop, you are overwriting the rows array each time ( i is reset to zero each time through the while loop) and MOVIEID.length is always 1 so each time through, you are re-creating a rows array with one element.
 
Scott Selikoff
author
Saloon Keeper
Posts: 4014
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Tim pointed out the for and while loop seem redundant, generally you just do "while (rs.next()) {}" in JDBC. Also, note that the number of records in your ResultSet is unavailable in most DBMS, so you tend to need a dynamic array such as an ArrayList over a typed array of Object[][] since you may not know the size of the results. For example, if your result was corrected it would throw an index exception if there were more than 10 records.

Lastly, is it so hard to create a Movie class? I don't think I've seen a 3-dimensional array of Object[][] in a very long time. Better structure would be List<Movie> initialized using the ArrayList<Movie>() constructor.
 
Dene Lamprecht
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you guys for replying. I am very new to Java but I think I might have an idea of what you are saying. As far as
Scott Selikoff wrote:create a Movie class
is this what you meant:
?

is it possible that anyone can give me a link to a tutorial regarding the ArrayList, because all I'm able to find is tutorials that has to do with user input into ArrayLists. I am struggeling to understand what I must do to load the ArrayList into my table.
PS: I am not allowed to use vectors for this.

Thank you
 
Scott Selikoff
author
Saloon Keeper
Posts: 4014
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vectors and ArrayLists are nearly identical, there's a million examples comparing them on the web.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic