1

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];
            }
        });
Eddie Martinez
  • 13,582
  • 13
  • 81
  • 106
Rajendra Arora
  • 43
  • 1
  • 1
  • 6
  • I recently created a small example for someone, though I [deleted that answer](http://stackoverflow.com/q/24740803/1057230)(__you need more reputation to see [this answer](http://stackoverflow.com/a/24859450/1057230)__), since it was not related to the question, though for helping in OP in some other aspect. You can look at it, just run the .jar file, [the whole project](https://www.dropbox.com/s/r9cct4kxns0rr6i/database.zip), though I am using derby, the database that comes with JDK by default, so you can run it without much fuss :-) – nIcE cOw Jul 23 '14 at 16:31

1 Answers1

2

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.

camickr
  • 321,443
  • 19
  • 166
  • 288