我一直在努力让我的JComboBox填充数据库中的列名,但没有成功。起初我在表格中加载了三个列名称放入其中,然后将其剥离为一个,以查看它是否可以正常工作。
然而我得到一个NullPointerException
有人可以就如何使这项工作给我指导吗?
感谢。
public BlankStock() {
conman = new ConnectionManager();
con = conman.CreateConnection();
initComponents();
BlankBox.setModel(fillBlankBox());
BlankBox.removeAllItems();
BlankBox.addItem("Please Select...");
fillBlankBox();
}
public DefaultComboBoxModel fillBlankBox() {
try {
String qry = "SELECT MCOBlanks FROM `blanks` WHERE MCOBlanks = 'blanks' ";
//Connection con = null;
// con = getConnection();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(qry);
System.out.println(rs.getStatement().toString());
ComboBoxModel cbm = new DefaultComboBoxModel();
DefaultComboBoxModel dcbm = new DefaultComboBoxModel();
while (rs.next()) {
Object data1 = BlankBox.getSelectedItem();
cbm.addListDataListener(BlankNo);
}
dcbm.addElement(BlankBox);
BlankBox.setModel(cbm);
rs.close();
stmt.close();
} catch (SQLException e) {
System.out.println(e);
}
// } finally {
// try {con.close();} catch (SQLException e){;}
// }
return cbm;