我也使用简单语句和一个结果集对象,但是当我试图将值填充到jcombobox时,它会引发nullpointerException,即使我检查过了!= null也...什么原因可以一个告诉我..
public void myInit()
{
try
{
//register driver
Class.forName("oracle.jdbc.driver.OracleDriver");
//establish the connection
con1 = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","virat");
if(con1!=null)
{
//create statement
st = con1.createStatement();
}
if(st!=null)
{
//execute login to get values to combobox
rs1 = st.executeQuery("select empid from employee");
}
if(rs1!=null)
{
while(rs1.next())
{
comboBox.addItem(rs1.getString(1));
}
}
}
catch(ClassNotFoundException cnf)
{
JOptionPane.showMessageDialog(null, cnf);
}
catch(SQLException se)
{
JOptionPane.showMessageDialog(null, se);
}
}