JCombobox中的ResultSet [英] ResultSet in JCombobox
本文介绍了JCombobox中的ResultSet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用SQL结果填充Jcombobox,但是为什么我在这里得到ArrayIndexOufOfBounds? JCombobox就像这样:countrybox = new JComboBox(countries);
I want to populate a Jcombobox with sql results but why am I getting an ArrayIndexOufOfBounds here? The JCombobox is like that: countrybox = new JComboBox(countries);
int x = 0;
String query = "SELECT UNIQUE country FROM criminals ORDER BY country ASC";
System.out.println(query);
Statement stmt = connection.createStatement();
ResultSet rset = stmt.executeQuery(query);
while (rset.next()) {
countries[x] = rset.getString(1);
x++;
}
推荐答案
无需临时存储.您可以直接使用ArrayList将项目直接加载到组合框中:
No need for temporary storage. You can load the items directly into the combo box with out using an ArrayList:
comboBox.addItem(...);
或者使用Vector而不是ArrayList,因为DefaultListModel无论如何都使用Vector来保存数据.
Or use a Vector instead of the ArrayList because the DefaultListModel uses a Vector to hold the data anyway.
这篇关于JCombobox中的ResultSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文