user1458401
user1458401

Reputation: 1

javafx 2.1 combobox

I used this code to get values from database but can get only one record but I want to put all records in to the combobox.

My code is:

try {
    stm = db.con.createStatement();

    rs = stm.executeQuery("select code from accounts");

    while (rs.next()) {
        for (int i = 1; i <= 5; i++) {
            ol = rs.getObject(i);
        }

    }
} catch (SQLException sqlException) {
}

ObservableList<Object> options = FXCollections.observableArrayList(ol);

final ComboBox code = new ComboBox();

code.getItems().addAll(options);

Upvotes: 0

Views: 455

Answers (1)

Howard Schutzman
Howard Schutzman

Reputation: 2135

The problem appears to be that your variable ol simply contains the last object that you extracted from the ResultsSet. It appears what you intended to do was something like the following:

ArrayList<Object> ol = new ArrayList<Object>();
while (rs.next()) { 
    for (int i = 1; i <= 5; i++) { 
        ol.add(rs.getObject(i)); 
    } 

} 

I am not sure if this does exactly what you want, but hopefully this demonstrates why you are only getting one object in your combo box.

Upvotes: 1

Related Questions