Rajendra Arora
Rajendra Arora

Reputation: 43

How to insert all database values into a column table list?

I've made my own phone book diary, and yes I could insert my values into dabatase, But the problem is I want to show that values into column list please see my pic

click here

At the moment my code is here to show the list and my all values from database want to insert into null place, i mean retrieve those database's values into Object[][] place.. how to do that? i want to know just the logics

here is codes:

jTable1.setModel(new javax.swing.table.DefaultTableModel(               
                new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
            },
            new String [] {
                "Name", "Mobile no.", "City", "Country"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            @Override
            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });

Upvotes: 1

Views: 608

Answers (1)

camickr
camickr

Reputation: 324207

i mean retrieve those database's values into Object[][] place

Don't attempt to do that. You have no idea how many rows of data you will have so you have no idea how big to make the array.

Instead you should:

  1. Create the DefaultTableModel with the "column names" and "zero rows of data". Read the API for the appropriate constructor.

  2. When you want to add data to the table you can use the addRow(...) method of the DefaultTableModel.

Upvotes: 2

Related Questions