当我试图将数据库号填充到jcombobox时,它显示nullponterexception是什么原因?

时间:2016-02-25 07:13:03

标签: java swing jdbc

我也使用简单语句和一个结果集对象,但是当我试图将值填充到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);            
    }

}

0 个答案:

没有答案