Forums Register Login

JTable output from db query

+Pie Number of slices to send: Send
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..
+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
 

Jhedzkie Skies wrote:


Try switching these two statements. You must first execute the query before you can get the results.
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
 

Maneesh Godbole wrote:



did. just showing only table column headers.

not showing table contents. :|
+Pie Number of slices to send: Send
Does tablePanel have BorderLayout?
Is there any row data coming from the DB after you invoke createModelFromResultset()?
+Pie Number of slices to send: Send
 

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

+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send


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.
+Pie Number of slices to send: Send
 

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.
Wait for it ... wait .... wait .... NOW! Pafiffle! A perfect tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 3764 times.
Similar Threads
JTable & JDBC
JTable
JTable
Refreshing JTable
JTable(!!!)
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 22:35:18.