get data from a Db display in combobox in java
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.
精彩评论