我希望组合框在运行时存储数据库中的名称,所以我创建了一个列表,但组合框显示错误...
List<String> s = new ArrayList<String>();
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:project","sa","123456");
Statement stmt= con.createStatement();
ResultSet rs=stmt.executeQuery("SELECT Name FROM company");
i=0;
while(rs.next()) {
s.add(rs.getString("Name"));
}
}
catch(Exception ex) { {
JOptionPane.showConfirmDialog(f,ex);
}
cb=new JComboBox(s);
}