开发者

setting items to a jComboBox

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜