Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

fxml ComboBox created in scene builder how to fetch data from database

TAJDINJan 9 2013 — edited Jan 10 2013
Hi Sir, How r u? Hope to be fine. Sir, I have a problem that i want to fetch data in fxml comboBox created in Scene Builder?

I have used this code in JavaFx 2.0 for comboBox and textField the code is

ComboBox studentRegId = new ComboBox();

try{
stm = db.con.createStatement();
rs = stm.executeQuery("select * from students order by s_reg_id asc");
while(rs.next()){
for(int i=1; i<=1; i++)
studentRegId.getItems().add(rs.getString("s_reg_id"));

}
}catch(SQLException sqlException){
}

final TextField sRegId = new TextField();

final String regId[] = new String[1000];
try{
stm = db.con.createStatement();
rs = stm.executeQuery("select * from students order by s_reg_id asc");
int a = 0;
while(rs.next()) {
regId[a] = rs.getString("s_reg_id");
a++; }
}catch(SQLException sqlException){
}
studentRegId.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>(){
public void changed(ObservableValue ov,Number value, Number new_value){
sRegId.setText(regId[new_value.intValue()]);
}
});

Now, the problem is that I want to use this code in Scene Builder fxml ComboBox .

Please Help Me!

I shall be very grate full to you for this kindness.

Regards
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 7 2013
Added on Jan 9 2013
2 comments
26,310 views