簡體   English   中英

將項目設置到jComboBox

[英]setting items to a jComboBox

我知道如何從數據庫獲取數據到Java應用程序,但是我的問題是將數據添加到JComboBox,我這樣做是:main.java:

`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();

這里的連接仍然為空。 是不是

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM