Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable output from db query  RSS feed

 
Aron Jhed Amiscosa
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there...

i would like to ask, is it possible to make a JTable show DB columns through query only?

i mean, like i would execute
select * from some_table
then the table would show up the contents..

just like how the mySQL query browser table works.. is it possible on a JTable?

because i've been using JTable with a custom model, but its contents are programmatically made. (built within the program)

i would like the table to be sort of a dynamic one that depends on queries. is there a possibility to make something like that?

i would like to get some knowledge and some ideas. (if it is possible)

thanks in advance..
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out camickr's http://tips4java.wordpress.com/2009/03/12/table-from-database/
 
Aron Jhed Amiscosa
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


hi. thanks for the reply.

i tried to use mr. camick's work.

here's my usage..



my code somewhat gives me a NullPointerException that points to this line of the ListTableModel



which part did i messed up? :O help.
 
Rob Spoor
Sheriff
Posts: 20895
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jhedzkie Skies wrote:

Try switching these two statements. You must first execute the query before you can get the results.
 
Aron Jhed Amiscosa
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:
Jhedzkie Skies wrote:

Try switching these two statements. You must first execute the query before you can get the results.


right. my bad. :|

now i need to put the table on my frame. but its not repainting.




am i doing it right? please help.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Aron Jhed Amiscosa
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:


did. just showing only table column headers.

not showing table contents. :|
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does tablePanel have BorderLayout?
Is there any row data coming from the DB after you invoke createModelFromResultset()?
 
Aron Jhed Amiscosa
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Does tablePanel have BorderLayout?
Is there any row data coming from the DB after you invoke createModelFromResultset()?


i put



and yes, there are row data from the db (i believe) because the db is not empty..

my current code for the whole method is this

 
Rob Spoor
Sheriff
Posts: 20895
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jhedzkie Skies wrote:

The loop skips past all records, so when you call ListTableModel.createModelFromResultSet(rs) the result set is already at the end and nothing will be put into the model.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Actually that comment is not accurate. What the code in that loop actually does is to really, really fetch the data from the database. So once it's finished, the result set cursor is at the end of the result set and there is no data left to be displayed in the table. Just don't do that.
 
Aron Jhed Amiscosa
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:
Jhedzkie Skies wrote:

The loop skips past all records, so when you call ListTableModel.createModelFromResultSet(rs) the result set is already at the end and nothing will be put into the model.


i see. that's why... im such a newbie on this. thanks you guys. its working cool right now. many many thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!