我正在尝试使用我设法做的数据库填充JComboBox
数据。问题是,每次选择一个条目时它都会填充。我如何解决这个问题,我需要填充一次。
public void writeSku() {
try{
Class.forName(dbClass);
connection = DriverManager.getConnection(dbUrl);
state = (Statement) connection.createStatement();
String query2 = "SELECT sku FROM drugs";
result = state.executeQuery(query2);
ResultSetMetaData meta = (ResultSetMetaData) result.getMetaData();
int columns = meta.getColumnCount();
while(result.next()){
for(int i =1; i<=columns; i++){
String skuValue = result.getString(i);
skuCombo4.addItem(skuValue);
}
}
} catch(ClassNotFoundException | SQLException ex){
JOptionPane.showMessageDialog(null,"Error"+ex);
}
}