• Post Reply Bookmark Topic Watch Topic
  • New Topic

Possible to add info directly from database to jtable

 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This might sound like a stupid question, I have checked some of the postings in this forum , but I have found nothing to really answer my question. Wondering if it is possible to directly pass data from a database to a JTable without having to store it in a Vector or Array.
The client cannot modify the info he will simply view it. The records may range from 1 to 100000. I know it needs to extend AbstractTableModel but im having a hard time visualizing how methods getValueAt() & setValueAt() would work???
Thank u for your time
 
Tracy Woo
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although I would not recommend to go the the database for fetching each cell value, here is one way to do it:
Write a stored procedure that takes an extra parameter index. This stored prodedure would fire an sql query and will skip all the row up to the index and then just return one row. Now, extract the column value using getString(column). You could also do the skipping of row outside the db but that might be slow. I don't know but I strongly suspect that SQL has some way of automatically doing this. In MySQL you can do something like:
SELECT * FROM `USER` LIMIT 30, 1
Remember that going to the db for each column value when you have 100000+ rows will increase the no. of db calls drastically.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!