2011-08-09 1 views
0

항목을 설정하지만 내 문제가하는 JComboBox에 데이터를 추가하고, 내가 이런 짓을 : main.java :난 자바 응용 프로그램 데이터베이스에서 데이터를 가져 오는 방법을 알고하는 JComboBox

`Interface itself = new Interface(); 
    itself.setComboBoxItems();` 

// 호출 방법 setComboBoxItems 여기

는 방법 setComboBoxItems()이다 :

public void setComboBoxItems() { 
      ResultSet rset = null; 
      Statement stmt = null; 
      Connection connect = null; 
      try { 
       stmt = connect.createStatement(); 
       rset = stmt.executeQuery("SELECT * FROM DB_Library.dbo.categories"); 
       while(rset.next()) { 
        String comboItem = rset.getString("categoryName"); 
        System.out.print("now combobox items will run!"); 
        categoriesComboBox.addItem(comboItem); 
       } 
      } catch (SQLException ex) { 
       System.out.print("error from set ComboBox: "); 
       Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex); 
      } 
     } 

하지만, 내가 해결할 수없는 나를 위해

를이 오류를 반환 여기

Connection connect = null; 
    try { 
     stmt = connect.createStatement(); 

연결 여전히 null 인 : 당신이 연결을하지 않았다처럼

+2

어떤 오류가 발생합니까? – u449355

+0

우리에게'ex.printStackTrace()'를 표시하십시오. – oliholz

+0

'인터페이스 자체 = 새로운 인터페이스();'는 새끼 고양이를 울게 만듭니다. – Qwerky

답변

1

그래서, 그것은 보인다. 안 그래?

+0

감사합니다 Andrey! 당신 말이 맞지만 여전히 JComboBox에 아무것도 나타나지 않습니다! – user743473

+0

@ user743473, 확인 했습니까? 결과 집합에 무언가가 포함되어 있거나 비어 있습니까? –