I want to create a combobox which takes names from database at runtime. So i created a empty string array but it throws an exception that arrayindexoutofbound. I think there's a mistake in initialization.....
String s[]=new String[0];
{
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[i]=rs.getString(1);
i++;
}
}
catch(Exception ex)
{
JOptionPane.showConfirmDialog(f,ex);
}
cb=new JComboBox(s);
}