• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable output from db query

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Darryl Burke wrote:Check out camickr's http://tips4java.wordpress.com/2009/03/12/table-from-database/



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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Aron Jhed Amiscosa
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maneesh Godbole wrote:



did. just showing only table column headers.

not showing table contents. :|
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic