Second SELECT statement causes app to hang
I am writing a piece of software using Java that consists of a fairly simple GUI to access a database. The first time the gui is generated, it requests data from the database using a default SQL statement. This default statement just returns all the values for the first two columns of a specific table. There is JTextField included in the GUI to search the table for specific entries.
I am using an adapted version of an example from Beginning Java 2 (JDK 1.3 edition) pages 1042-1052. I have pratically copied the ResultsModel class word-for-word, the major differences are how I've implemented the GUI. I am still using a JTable to display the results, but I am using a Thread to retrieve the new results and update the table.
My problem is this: The first time the Thread accesses the database, the table is updated fine. Any subsequent attempt to display another ResultModel causes the program to hang. By careful placement of prinln() statements, I have worked out that it is the fireTableChanged() method that is actually responsible. The Thread seems to retrieve the new ResultSet and store it in the ResultsModel class, but when the fireTableChanged() method is called, it stops execution.
I am writing my code using NetBeans 3.5.1, running through SuSE Linux 8.1. The database is implemented in MySQL, and is stored on another machine, connected to my own using a cross-over cable. I cannot figure out why the JTable does not successfully update a second time, any suggestions would be most appreciated.
If you think posting my code would help, just let me know - I would have posted it now, but it's a bit messy at the moment!
Thank you in advance.
Peter Green.
|