![](/img/trans.png)
[英]Setting a tooltip for a value from JComboBox's Items as CellEditor in JTable
[英]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.