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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:43:39+00:00 2026-05-27T11:43:39+00:00

I want to bind mysql table content with JTable . I have connected sucessfully.

  • 0

I want to bind mysql table content with JTable. I have connected sucessfully. I set table row and width as 500. It will shows 500 rows including data and empty. Now I want to view only data. I don’t want to view empty rows.

Please help me

My application get slow after insert a method getRowCountFromDB()..

class AbstractTableEmployee extends AbstractTableModel {

    int row2;

    private String[] columnNames = { "ID", "Name", "Company", "Department", "Location", "Mobile NO" , "Shift" };
    private Object[][] data =  new Object[500][500];


    public int getColumnCount() {
        return columnNames.length;
    }

    public int getRowCount() {
        int row = 0;
        try {
            row =  this.count();
        } catch (SQLException ex) {
            Logger.getLogger(AbstractTableEmployee.class.getName()).log(Level.SEVERE, null, ex);
        }
        return row;
    }

    public String getColumnName(int col) {
        return columnNames[col];
    }

    public Object getValueAt(int row, int col) {
        return data[row][col];
    }

    public void setValueAt(Object value, int row, int col) {
        data[row][col] = value;
        fireTableCellUpdated(row, col);
    }
    private int getRowCountFromDB() throws SQLException {
        Connection con  = (Connection) DBConnection.getDBConnection();
        int row = 0;
        Statement st = null;
        ResultSet rs = null;
        String Sql = "Select * from Employee_Master where status = 'Active'";
        try {
            st = (Statement) con.createStatement();
            rs = st.executeQuery(Sql);
            while (rs.next())
            {
                row++;
            }
        }
        finally {
            con.close();
            rs.close();
            st.close();
        }
        return row;


    }

    private int count() throws SQLException {
        return this.getRowCountFromDB();
    }
}

Thanks in advance.

  • 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-05-27T11:43:40+00:00Added an answer on May 27, 2026 at 11:43 am

    The documentation for JTable gives the following example for how to use a table with a custom table model.

    TableModel dataModel = new AbstractTableModel() {
        public int getColumnCount() { return 10; }
        public int getRowCount() { return 10;}
        public Object getValueAt(int row, int col) { return new Integer(row*col); }
    };
    JTable table = new JTable(dataModel);
    JScrollPane scrollpane = new JScrollPane(table);
    

    This is the minimal implementation that you’d have to provide.

    Edit:

    See 3.3.4.8 Counting Rows in the MySQL Reference for information on how to get a row count efficiently. It seems to me that you’re fetching an entire table, when all you want is a number.

    You’d want something along the lines of

    Select COUNT(*) from Employee_Master where status = 'Active'
    

    and then just reading that value.

    As for your data, I see no reason for it to have 500 columns, given that your table seems to have only 7.

    Anyway, depending on the size of your table, you might not want to have all the data in there at once. If that’s the case, you can always fetch and cache chunks of rows, according to where in the JTable your user is scrolling. You could use LIMIT for that.

    For some other ideas and tips, you should also take a look at this question which covers a similar problem.

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

Sidebar

Related Questions

I have a mysql table, I want to check if a row exists where
i have an input element, and i want bind both change and keypress event
I have a datasource that I want to bind to a listview that has
So I have this function that takes all the users from an MySql table
I have a table with these columns: win, los, id ... I want to
I have an ASP.net project I'm looking at and they want to use MySQL.
I have dynamically create usercontrol, this usercontrol i want bind into DataTemplate. EX: usercontrol:
I want to bind a MySQL database to my WPF GridView. But this doesn't
I have a VPS and I want to make mysql DB accept connection externally
I have three tables set up in a MySQL database called event, status and

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.