Skip to main content

Refresh Jtable?

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
blythe
Offline
Joined: 2011-05-25

Hi everyone. I am newbie here and wants to ask a question. I have a jtable who has values from a database. I want to have a refresh button so that when I press it, it will refresh the table. Here is the code.

String sql = "Select * from transaction";
PreparedStatement stmt = conn.prepareStatement(sql);
ResultSet rs = stmt.executeQuery();

for(int x=0;rs.next();x++){
table.setValueAt(rs.getString("customername"), x, 0);
table.setValueAt(rs.getString("description"), x, 1);
table.setValueAt(rs.getString("typepaper"), x, 2);
table.setValueAt(rs.getString("assigned"), x, 3);
table.setValueAt(rs.getString("comments"), x, 4);
table.setValueAt(rs.getString("month"), x, 5);
table.setValueAt(rs.getString("day"), x, 6);
table.setValueAt(rs.getString("Year"), x, 7);
table.setValueAt(rs.getString("copies"), x, 8);

I know some codes about table.setModel(new javax.swing.table.DefaultTableModel()); will refresh your table but I can't get it to work. Can someone help me refresh my table?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rajivbhati12
Offline
Joined: 2011-07-23

hey buddy,
I am not very specialist in java, i am a newbee too & still learning
However, i know the solution to your problem is UIManager
and Repaint
Search over google with these 2 words and you will get lots of example describing what you wish to do.
Also, I have posted question in this forum and still waiting for the answer or direction. Surprise!!!
Regards,
Rajiv