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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:08:49+00:00 2026-05-27T00:08:49+00:00

we had a table called data in database and we want to retrieve and

  • 0

we had a table called data in database and we want to retrieve and display all the data in a JTable component using NetBeans IDE. Every rows in the database should be display in the jtable.

  • 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-27T00:08:50+00:00Added an answer on May 27, 2026 at 12:08 am

    Also, keep in mind that MVC is the name of the game. Extend an AbstractTableModel in order to create a model that will provide data to your JTable.

    You will need to implement the following methods:

    public int getRowCount()
    public int getColumnCount() and 
    public Object getValueAt(int rowIndex, int columnIndex)
    

    and finally set your model to the JTable:

        myJTable.setModel(new MyModel());
    

    Something like this:

    public class MyModel extends AbstractTableModel {
    
        private Connection con;
        private Statement stmt;
        private ResultSet rs;
    
        public MyModel () {
    
            try {
                Class.forName("com.mysql.jdbc.Driver");
                try {
                    con = DriverManager.getConnection("jdbc:mysql://localhost:3306/databasename?useUnicode=true&characterEncoding=UTF-8",
                            "root", "password");
                    stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
                    rs = stmt.executeQuery("select * from tablename");
    
                } catch (SQLException e) {
                    String msg = "MyModel(): Error Connecting to Database:\n"
                            + e.getMessage();
                    System.out.println(msg);
                }
            } catch (ClassNotFoundException e) {
                String msg = "The com.mysql.jdbc.Driver is missing\n"
                        + "install and rerun the application";
                System.out.println(msg);
                System.exit(1);
            } finally {
    
            }
        }
    
        public int getRowCount() {
    // count your rows and return 
            return count;
        }
    
        public int getColumnCount() {
    // how many cols will you need goes here
            return 3;
        }
    
        public Object getValueAt(int rowIndex, int columnIndex) {
            try {
                rs.absolute(rowIndex + 1);
                switch (columnIndex) {
                    case 0: 
                        return rs.getInt(1);
                    case 1:
                        return rs.getString(2);
                    case 2:
                        return rs.getString(6);
                    default:
                        return null;
                }
            } catch (SQLException ex) {
                System.out.println(ex.getMessage());
            }
            return null;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We previously had a database in MySQL. In it, we had a table called
Say if I had a table of books in a MySQL database and I
I am trying to pull out data from the table I had from the
I am using Microsoft SQL Server. I have a Table which had been updated
I had to delete all the rows from a log table that contained about
In our inventory database (SQL Server 2008 std edition) we have a table (called
In SharePoint 2003 and 2007, there was a table called AllLists which had a
I have a log table in my database which holds all user actions. In
I have a sql table called predictions with data as below Week Player Points
I have a table called emaildata consisting of 4 columns emailaddress, domainname, data 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.