开发者

get data from a Db display in combobox in java

开发者 https://www.devze.com 2023-02-27 03:15 出处:网络
hi everyone i have this code but don\'t know why it doesn\'t work!开发者_Go百科 rset = stmt.executeQuery(\"SELECT categoryName FROM DB_Library.dbo.categories\");

hi everyone i have this code but don't know why it doesn't work!开发者_Go百科

rset = stmt.executeQuery("SELECT categoryName FROM DB_Library.dbo.categories");
while (rset.next()) {
    String s = rset.getString("categoryName");
    jComboBox1.addItem(rset.getString(s).trim());
}

don't show me any thing * This code is printing all the items in database:

rset = stmt.executeQuery("select * from DB_Library.dbo.categories");
while (rset.next()) {
    String s = rset.getString("categoryName");
    System.out.println(s );
}

any help?


Try the following:

rset = stmt.executeQuery("SELECT categoryName FROM DB_Library.dbo.categories");
while (rset.next())
{
    String s = rset.getString("categoryName");
    jComboBox1.addItem(s.trim());
}


The combobox items must be loaded before it is painted in the screen.

0

精彩评论

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