开发者

setting items to a jComboBox

开发者 https://www.devze.com 2023-03-27 05:34 出处:网络
i know how to get data from Database to the java applications but my problem is adding the data to a JComboBox,i did this:

i know how to get data from Database to the java applications but my problem is adding the data to a JComboBox,i did this: main.java:

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

//calling the method setComboBoxItems

here is the method setComboBoxItems():

public void setComboBoxItems() {
            ResultSet rset = null;
            Statement stmt = null;
            Connection connect = null;
            try {
                stmt = connect.cr开发者_如何学CeateStatement();
                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);
            }
        }

but it return this error for me that i cannot solve,


So, it looks like you didn't get a connection:

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

here is connect is still null. isn't it?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号