File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable won't display records from database

 
Michael Monchu
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am trying to display data from the database on the table, using the Vector approach. I have verified that the Vector is loaded by printing the data on the console. I am not sure why the table won't display the records.
Below is the code:


I would appreciate any form help or advice to a link where I can get help.

Regards
Michael
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the Swing forum. Please UseCodeTags when posting code. You can edit your post with the button.
 
Rob Camick
Ranch Hand
Posts: 2473
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once a TableModel has been added to the table all updates to the model should be done through the TableModel.

So your code should be restructured to look something like:



Your populateTable() method would need to change to create and then return the DefaultTableModel.
 
Michael Monchu
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob

I have modified the code the way you suggested, and it still doesn't display.



I don't know what is it that I am doing wrong. Please help.

Regards
Michael
 
Rob Camick
Ranch Hand
Posts: 2473
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See Table From Database.

The first part you don't need to worry about (unless you want to try that more complicated solution).

However, the second part contains the "Table From Database Example", which does exactly what you are trying to do. All you need to do is customize the SQL and it should work. Once you get that example working you can compare that code with your code to see what the different is.

If you need more help then you need to post a SSCCE. Of course in your SSCCE you can't include the database code, so you would replace that method with hard coded data that creates the DefaultTableModel. Once you get it working with hard coded data you should be able to replace that code with the SQL code.
 
gorgoro rogers
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Monchu wrote:Hi

I am trying to display data from the database on the table, using the Vector approach. I have verified that the Vector is loaded by printing the data on the console. I am not sure why the table won't display the records.
Below is the code:


I would appreciate any form help or advice to a link where I can get help.

Regards
Michael


replace this and try
public void populateTable(){
ResultSet res;

String select = "Select * from LIBRARY.TABLE";<-------------------------------------------String select
try{
PreparedStatement rtvStmt = conn.prepareStatement(select);
res = rtvStmt.executeQuery(select);<-----------------------------------------------Put here String select
ResultSetMetaData md = res.getMetaData();
int columnCount = md.getColumnCount();


you send an empty executequery you have to fill it .try it .replace also were you have to
 
Michael Monchu
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob

I used the example that you have provided, and it's working perfectly. Thanks a lot.

Regards
Michael
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic