0

Seeking help again...

I have a query that I run, when I run it in Netbeans it's very fast (less than a second) and about a second to display the info. When I run the same query and populate a JTable (defined at design time, not runtime), it is very slow.

DB has about 600 records - delay of 20 seconds Limit to 10 - delay of about 10 seconds Limit to 1 - delay of about 3 seconds

Is there a way to make the Tablemodel "quicker"?

I have contemplated paging, but even a delay of 10 seconds for about 10 records is not great - something must be inherently wrong with my code (sorry, complete Java Noob).

Below is my code:

String SQL = "SELECT RecTable.ipkRecNo, RecTable.RecName order by ipkRecNo";

DefaultTableModel defaultModel = (DefaultTableModel) jTable1.getModel();
Statement stmt = con.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE   ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery( SQL );

int i = 0; 
String PreviousKey = "";
while ( rs.next( ) ) {
i++;
String MyRecNum = "";
String MyRecName = "";

if (rs.getString(1).trim() == PreviousKey.trim() ) {
} else {

MyRecNum = rs.getString(1);
MyRecName = rs.getString(1);

defaultModel.addRow(new Object[]{MyRecNum,MyRecName}); //1307
} 
QS Train
  • 95
  • 2
  • 12
  • Possible duplicate of [*AbstractTableModel GUI display issue*](http://stackoverflow.com/q/34738845/230513). – trashgod Jul 19 '16 at 05:25
  • Query the database in the background, for [example](http://stackoverflow.com/a/34742409/230513). – trashgod Jul 19 '16 at 05:26

1 Answers1

0

Javadoc for addRow method states:

Inserts a row at row in the model. The new row will contain null values unless rowData is specified. Notification of the row being added will be generated.

So, 1307 times event is generated. and that makes your program slow.

Azodious
  • 13,752
  • 1
  • 36
  • 71