I'm working from the tutorial at:
http://www.netbeans.org/kb/articles/mysql-client.html#db08But I've slightly changed things. Right now I'm getting a run-time
NullPointerException probably due to the JTable carsTable.setModel()
method returning an empty array.
I suppose I should print out the array and see what's in it.
However, if I could get a pointer for:
InsertTable.initComponents(){
...
ResultSet resultSet = MyDBConnection.getInstance().getCars();
//what do I do with resultSet?
carTable.setModel(CarTableModel.getInstance());
jScrollPane1.setViewportView(carTable);
...
}
I've checked out the underlying db from MySQL and it looks fine. I
suppose that I could drop the GUI and just print some queries, but I've
already done that in a previous project and don't think that's the
problem.
I suppose one thing I could do would be to print the contents of
CarTableModel, but I'm reasonably sure that they're ok:
thufir@arrakis:~$
thufir@arrakis:~$ cat NetBeansProjects/cars/src/a00720398/model/
CarTableModel.java
package a00720398.model;
import a00720398.controller.*;
import java.sql.*;
import java.util.logging.*;
import javax.swing.table.*;
@SuppressWarnings({"serial", "unchecked"})
public class CarTableModel extends DefaultTableModel {
private static final TableModel INSTANCE = new CarTableModel();
private CarTableModel() {
try {
init();
} catch (SQLException ex) {
Logger.getLogger(CarTableModel.class.getName()).log
(Level.SEVERE, null, ex);
}
}
public static TableModel getInstance() {
return INSTANCE; //maybe put some System.out.println here
}
public void init() throws SQLException {
dataVector.add(MyDBConnection.getInstance().getCars());
}
}
thufir@arrakis:~$
thanks,
Thufir