Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7944309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:30:54+00:00 2026-06-04T00:30:54+00:00

I’m populating data from my database into my JTable. After I add new data

  • 0

I’m populating data from my database into my JTable. After I add new data and press Refresh button, I want to remove the existing row displayed on table before retrieving the new data. How can I remove the existing row?

Here is the original table with data [a,1].

Original

This is the table after I add new data [b,1] and press refresh button. The original data [a,1] is still shown in the table:

After insert

JButton refreshButton = new JButton("Refresh");
refreshButton.setBounds(188, 248, 101, 23);
panel.add(refreshButton);

refreshButton.addActionListener(new ActionListener() 
{                        
    public void actionPerformed(ActionEvent ae)
    {

    DefaultTableModel model = new DefaultTableModel(data,columnNames);
    int rowCount = model.getRowCount(); 

    for (int x = 0; x <=rowCount; x++)
    {
        model.removeRow(x);
    }


        try
        {                       
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/watchlist","root","root");

            String sql = "SELECT * FROM watchlist";
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery(sql);
            ResultSetMetaData md = rs.getMetaData();    


            int columns = md.getColumnCount();  

            while (rs.next())
            {   
                Vector row = new Vector(columns);

                for (int i=1; i <= columns; i++)
                {
                    row.addElement( rs.getObject(i) );              
                    System.out.println( rs.getObject(i).toString());        
                }                           

                data.addElement(row);   

                table.revalidate(); 
                table.repaint();
                panel.repaint();

            } // end while  

        } // end try

        catch (Exception e){
        }
    }

});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:30:55+00:00Added an answer on June 4, 2026 at 12:30 am

    I think that I saw this question,

    1) search for ResultsetTableModel / TableFromDatabase (better)

    • (if Database Connection (so hard and lazy action) isn’t closed during Applications lifecycle)

    a) replace JTable contents

    b) works with embeded Db of database placed in intranet immediatelly

    • dis

    all processes is durring EDT, then GUI waiting for SQL statement

    for most code examples required to move Xxx.close to the finally block

    2) most complex workaround you have to use SwingWorker, better and easiest way is to load data from Runnable#Thread

    3) you can remove row(s) from TableModel,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
I want to construct a data frame in an Rcpp function, but when I
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.