Mickeys
asked on
Reading database with a string array
I am wondering how I can create a String array without knowing how big it should be.
Look at my code
Look at my code
public String[] getAirports() {
String[] temp = new String[100];
try {
mStmt = mCon.createStatement();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
if (mStmt.execute("SELECT * FROM `mylab3database`.`airport")) {
mRs = mStmt.getResultSet();
} else {
System.err.println("select failed");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
for (int i = 0; mRs.next(); i++) {
temp[i] = mRs.getString(1);
System.out.println(temp[i]);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return temp;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can create ArrayList and accumulate yours string to ArrayList
I you then need really and array you can coy arraylist to array