1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| public static void comboBox(){
String[] table = new String[145];
int i = 0;
String country = "";
String data = "jdbc:odbc:WorldEnergy";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(
data, "", "");
Statement st = conn.createStatement();
ResultSet rec = st.executeQuery(
"SELECT DISTINCT Country " +
"FROM Coal " +
//"WHERE " + "(Country='" + arguments[0] + "') " +
"ORDER BY Country");
While(rec.next()) {
System.out.println(i + ":" + rec.getString(1));
//country = rec.getString(1);
table[i] = rec.getString(1);
i++;
}
st.close();
} catch (SQLException s) {
System.out.println("SQL Error: " + s.toString() + " "
+ s.getErrorCode() + " " + s.getSQLState());
} catch (Exception e) {
System.out.println("Error: " + e.toString()
+ e.getMessage());
}
} |