Hey folk, I'm wondering if you guys can help me. I'm from a PHP background so I'm not too sure if I'm looking at this the wrong way - but I've grabbed some results from a database and need to put them into an array which I can send back to a JComboBox.
First of all, is it not possible to send the resultset back to the JComboBox in the necessary array? Or do I have to create a seperate array variable, loop through the results adding each result into newly created array?
The code I've got so far looks like this:
Code:...
try {
sql = "SELECT title FROM domains";
rs = exec.getResults(sql);
rs.last();
totRows = rs.getRow();
String[] domainList = new String[totRows];
for (int i = 0; i < domainList.length; i++) {
domainList[i] = rs.getString(i); //This line doesn't actually work at the moment?
}
return domainList;
} catch (Exception e) {
String[] domainError = { "Error returning Domains", };
return domainError;
}
...
Is it not easier (or is it even possible in Java) to do the following?
Many thanks in advance!Code:..
String[] domainList = new String[totRows];
while(rs.next()){
//append to domainList array
}
return domainList;
...

