• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to fill data in a JTable with database?  RSS feed

 
Arian Gerryts
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there
I would like some help with filling a JTable with data that I retrieved from a database
The JTable has 5 columns.

this is what I have done so far.


How would I know proceed to fill the JTable with the resultSet(priceAccording).

Kind regards

 
Campbell Ritchie
Marshal
Posts: 56595
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn’t fill anything at this stage. you should get those data into objects, and get those objects into some sort of collection or Collection. You have got a ResultSet which you are iterating, putting the values into local variables which go out of scope before you use them.
Then you are trying to split an empty String ( )

Start by printing out those values from the ResultSet in that loop. Then put them into some sort of data transfer object, which you would of course design specifically for this application, and print each data object as you go through the loop. Then consider putting them into some sort of collection as appropriate. Print that collection out. Once you have got all those stages working, you can consider a JTable.
Why have you got the price as a double? It should either be a BigDecimal (corresponding the the SQL DECIMAL type) or it is whole numbers of $£€etc and it should be an int or a long.

Also, avoid such long lines in posts inside code tags; they are difficult to read.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!