Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why does my JTable not display data (Oracle/Java)?  RSS feed

 
Jason Smit
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have deployed my prototype application to a production environment to test and see if the application does what it is suppose to.

I noticed that when I do a SELECT * FROM table_name, it does not return any data.
But when I do a SELECT * FROM table_name WHERE rownum < 10 for example, the data returns.

I did a count on the number of rows in this table:
1072316

Are there any limitations with regards to displaying data on a JTable?
 
Stevens Miller
Bartender
Posts: 1444
30
C++ Java Netbeans IDE Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTable is pretty clever about retrieving data, typically limiting what it retrieves to what it needs for its on-screen display. It doesn't actually store all those rows (well, it might, depending on the model you use, but that's getting ahead of ourselves).

At first guess, I'm wondering if you are simply not waiting long enough for that select to return your data. Does your program actually exit or otherwise confirm for you that the select statement has completed its retrieval? A million records is not that overwhelming, but, depending on a lot of factors, it might take a little while to retrieve into a data structure.

If you could provide your code, that would help a lot.
 
Jason Smit
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stevens Miller wrote:JTable is pretty clever about retrieving data, typically limiting what it retrieves to what it needs for its on-screen display. It doesn't actually store all those rows (well, it might, depending on the model you use, but that's getting ahead of ourselves).

At first guess, I'm wondering if you are simply not waiting long enough for that select to return your data. Does your program actually exit or otherwise confirm for you that the select statement has completed its retrieval? A million records is not that overwhelming, but, depending on a lot of factors, it might take a little while to retrieve into a data structure.

If you could provide your code, that would help a lot.


Hi, I did wait because I too also thought it was just taking longer than it should. But this is not the case.
I also noticed when I exported the jtable data to CSV (using API, JXLS), the data is not exported.

However this is different and works if i just select a few records from the table.

The way the application works :
you click a button, and it returns
it then sets the jtable visible after retrieving the data. The JTable does display but it does not retrieve the data-it just shows the dummy values that are there by default (i added these).



 
Stevens Miller
Bartender
Posts: 1444
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's step back a bit. Looks to me like you're expecting the data to become available to the table with this line:

I'd suggest replacing that with something else, to see if you are successfully populating the table's model with data, and that you are able to see your data on the screen. If so, then your "DbUtils.resultSetToTableModel()" method should become your focus. Also, can you verify that rs actually has any data in it? (I'm less suspicious about that, since an empty result set should show as an empty table, but it's easy to see if you at least have data in rs, so why not check?)
 
Paul Clapham
Sheriff
Posts: 22491
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jason Smit wrote:Are there any limitations with regards to displaying data on a JTable?


You suggested that you wanted to display over a million records in the JTable. So it may be that you're running out of memory, or it may be that it takes an absurd amount of time to do that, but at any rate... Do you really want to see a million records? Can you imagine trying to scroll down through that table?
 
Stevens Miller
Bartender
Posts: 1444
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul's point is well taken. If you have a scrollbar that's a thousand pixels in the vertical direction, a million-record table is going to scroll a thousand records for each single pixel your scrollbar's bubble (or "thumb," if you call it that) moves. Now, I can imagine a few reasons to want to load up a thing like that, with maybe more fine-grained scrolling being enabled when you get close to the record(s) you want. But, this goes back to my suggestion that you replace the RecordSet as the source of the model with something else. See if you can create your table with a million records from any source, and leave your SQL/database/RecordSet issues for later. When debugging, especially "silent" bugs like this one, I use a divide-and-conquer approach. That is, I keep eliminating things until the bug goes away (or, at least, the behavior I get matches what I expect of my simplified program). Then, I start adding things back, incrementally, moving towards my original situation, until my bug returns (or, at least, the behavior I get no longer matches what I expect of my simplified program). This is akin to a binary search in a sorted array, if that helps illustrate my approach any.
 
Jason Smit
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stevens Miller wrote:Paul's point is well taken. If you have a scrollbar that's a thousand pixels in the vertical direction, a million-record table is going to scroll a thousand records for each single pixel your scrollbar's bubble (or "thumb," if you call it that) moves. Now, I can imagine a few reasons to want to load up a thing like that, with maybe more fine-grained scrolling being enabled when you get close to the record(s) you want. But, this goes back to my suggestion that you replace the RecordSet as the source of the model with something else. See if you can create your table with a million records from any source, and leave your SQL/database/RecordSet issues for later. When debugging, especially "silent" bugs like this one, I use a divide-and-conquer approach. That is, I keep eliminating things until the bug goes away (or, at least, the behavior I get matches what I expect of my simplified program). Then, I start adding things back, incrementally, moving towards my original situation, until my bug returns (or, at least, the behavior I get no longer matches what I expect of my simplified program). This is akin to a binary search in a sorted array, if that helps illustrate my approach any.


I am still a newbie at this Java world, hence me posting to Beginning Java group.

By default, there is this custom code for the Jtable:


By default, the data does display these values (i.e. null), and column headers (Custom_001,Custom_002,Custom_003,Custom_004), so the JTable should be working.

I am not really sure what I could substitute the result set with. Can you provide an example or point me to a nice tutorial ;).
 
Stevens Miller
Bartender
Posts: 1444
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a good tutorial that worked well for me.
 
Paul Clapham
Sheriff
Posts: 22491
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would also do my testing with a ResultSet containing 10 records rather than a million records. That way you can concentrate on the actual problem and not have to worry about whether you're overwhelming something with volume. It's a lot easier when you have fewer possibilities to chase down when testing.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!