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 8201385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:47:40+00:00 2026-06-07T06:47:40+00:00

The purpose of the application is to query a table, and take that information

  • 0

The purpose of the application is to query a table, and take that information and update a JTable. Right now the ThreadTask() is able to query the table and obtain the information. My question is how do I update the JTable GUI object with the information obtained from the database?

    public class AdminManager extends JFrame {

        public static void main(String[] args) throws InterruptedException {
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    try {
                        AdminManager frame = new AdminManager();
                        frame.setVisible(true);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
            });

            // Setup connection pool

            ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor();
            exec.scheduleAtFixedRate(new ThreadTask(connection), 2000, 100, TimeUnit.MILLISECONDS);
    }
        /**
         * Create the frame.
         */
        public AdminManager() {
            // Setup GUI

            DefaultTableModel model = new DefaultTableModel();
            model.addColumn("#");


            tableQueue = new JTable(model);
            tableQueue.getColumnModel().getColumn(0).setPreferredWidth(3);
            scrollPane.setViewportView(tableQueue);

        }
    class updateTable extends SwingWorker<Void, String> {
        @Override
        protected Void doInBackground() throws Exception {
            model.addRow(new Object[]{order_num});
            return null;
        }

    }
}
class grabData implements Runnable {
    private Connection connection;
    private DefaultTableModel model;
    private String order_num;

    public grabData(Connection c, DefaultTableModel m) {
         connection = c;
         model = m;
    }

    @Override
    public void run() {
       System.out.println("Working ... ");
       String sql = "SELECT * FROM order_queue;";
       Statement st;
       try {
           st = connection.createStatement();
           ResultSet rs = st.executeQuery(sql);
            while(rs.next()) {
                order_num = rs.getString("order_num");
                System.out.println(order_num);
                updateTable.execute()
            }
       } catch (SQLException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }   
   }
  • 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-07T06:47:44+00:00Added an answer on June 7, 2026 at 6:47 am

    If you are adding rows to a TableModel object that is held by a visualized JTable, then you must do so on the Swing event thread, the EDT. If you’re creating a completely new TableModel one that isn’t visualized, then I think it is safe to fill it off of the EDT, and then set it as the JTable’s model on the EDT.

    One consideration, if you want to add rows the JTable as they become available, consider using a SwingWorker<Void, RowObject>, and then pass the RowObject obtained in the while (rs.next()) { via a publish/process method pair.

    Edit:
    You could just skip the SwingWorker and just queue up adding the table’s row on the EDT:

    while(rs.next()) {
        final String order_num = rs.getString("order_num");
        // System.out.println(order_num);
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            model.addRow(new Object[]{order_num});
          }      
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that used another php cms system, which I am now
The situation is this: a table that is used in a query (name it
The purpose of my application is to pick some localized strings from an assembly.
My application does not fit into the general purpose RDBMS schema category, I do
In my application i am using t:commandSortHeader for sorting purpose, is it possible to
I'm developing a web application myself to follow some rssfeeds. My purpose is just
I have an application in which you can accept friend request. For this purpose
I have collectionView in my wpf application. For sorting purpose, I add four SortDescriptions
I'm working on embedding Python in our test suite application. The purpose is to
My Twitter application is based on a secured twitter account and should be able

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.