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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:36:35+00:00 2026-06-17T08:36:35+00:00

Here is a class which deals with the process of Table filtering //Class DbUtils

  • 0

Here is a class which deals with the process of Table filtering

//Class DbUtils

public class DbUtils {
    public static TableModel resultSetToTableModel(ResultSet rs) {

        try {
        ResultSetMetaData metaData = rs.getMetaData();
        int numberOfColumns = metaData.getColumnCount();
        Vector columnNames = new Vector();

        for (int column=0; column < numberOfColumns; column++) {
            columnNames.addElement(metaData.getColumnLabel(column + 1));              
        }
        Vector rows = new Vector(); 
        while(rs.next()) {
        Vector newRow = new Vector(); 
        for (int i =1; i <= numberOfColumns; i++) {
        newRow.addElement(rs.getObject(i));
        }
        rows.addElement(newRow);
        } 
        return new DefaultTableModel(rows,columnNames);

       }  catch (Exception e) {
          e.printStackTrace();      
         return null; 
    }



}

}

I have a method which updates a Job Table in class Job_GUI, arguments passed in are sql statements from which table_job is populated. what sql statement is passed in depends on which JTabbedPane is selected taking index value into account. and this is where my problems lies.

//Class Job_GUI

 public void UpdateJobTable(String sql) {
    try {

    pst = conn.prepareStatement(sql); 
    rs = pst.executeQuery();

    table_job.setModel(DbUtils.resultSetToTableModel(rs));
    table_job.getColumnModel().getColumn(0).setPreferredWidth(50);
        table_job.getColumnModel().getColumn(1).setPreferredWidth(140);
        table_job.getColumnModel().getColumn(2).setPreferredWidth(170);
        table_job.getColumnModel().getColumn(3).setPreferredWidth(80);
        table_job.getColumnModel().getColumn(4).setPreferredWidth(120);

}
    catch (Exception e ) {

        JOptionPane.showMessageDialog(null, e);
    } 

    finally {

         try {

          pst.close();
          rs.close();
        } catch (Exception e) {

        }
    }
} 



private void JobTabbedPaneStateChanged(javax.swing.event.ChangeEvent evt) {                                           
    JTabbedPane sourceTabbedPane = (JTabbedPane) evt.getSource();
    int index = sourceTabbedPane.getSelectedIndex();
    if (index == 0) {

       jobTableInit(); 

    }
    else if (index == 1) {
        fillCombo();

    }

    else if(index==2) {
        try {
            sql = "SELECT Job.jobID as 'Job ID', Employer.name as'Company', Job.title as 'Role', Job.description as 'Description', Job.type as 'Type', Job.benefits as 'Benefits', Job.closing as 'Closing Date' FROM Job INNER JOIN Employer ON Job.employerID=Employer.employerID ORDER BY Employer.name";
            pst = conn.prepareStatement(sql);
            rs = pst.executeQuery();
            TableModel model = DbUtils.resultSetToTableModel(rs);
            table_job.setModel(model);
            final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
            table_job.setRowSorter(sorter);
            JScrollPane pane = new JScrollPane(table_job);
            searchJob.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e) {
                String text = keyword.getText(); 
                if (text.length() == 0) {
                sorter.setRowFilter(null);
                 } else {
                  sorter.setRowFilter(RowFilter.regexFilter(text));


                  }
                 }             
             });

        }

        catch (Exception e) {
           e.printStackTrace();                
        }


    }

When I am in index 2 mode, the table_job content is wiped away, i.e. going back to index 0, table becomes empty, whereas intially it was full of data. When I am in index 2, I don’t want table_job to be empty, rather still continue to show data, unless a keyword is entered in JTextField, adjust table_job to search matches. but table_job is not showing anything. what have I done wrong in the code snippet in if block for index 2, perhaps I am wrong elsewhere?

  • 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-17T08:36:36+00:00Added an answer on June 17, 2026 at 8:36 am

    For reference, this complete example illustrates using setModel() to change a TableModel en bloc. Updates are automatic. Also consider using the methods of DefaultTableModel to alter the model.

    image

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

Sidebar

Related Questions

Here's sample model classes, which being use with Entity Framework Code First: public class
I have a fairly straightforward Java class here which creates 2 thread pools.... Connects
I have a container class which uses boost::optional to hold the value. Here is
Here is my problem, I have a class which have a object who throw
Alright so here is the question. I have a user class which contains a
So i have a class name repository which is just a simple array.Here is
I am in the process of designing a simple Java application which deals with
I found this code here class Usable; class Usable_lock { friend class Usable; private:
Given the code from here : class lazy_init { mutable std::once_flag flag; mutable std::unique_ptr<expensive_data>
What am I doing wrong here: class Helo { // main: generate some simple

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.