Reputation: 43
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
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
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:
Create the DefaultTableModel with the "column names" and "zero rows of data". Read the API for the appropriate constructor.
When you want to add data to the table you can use the addRow(...)
method of the DefaultTableModel
.
Upvotes: 2