I have a question. How can I do asynchrous database in JavaFX. I know that exist SwingWoker but I read that I can't use this in JavaFX. I read about Task but I can do convert the result to ObservableList but I need normal LinkedList. I'm trying conntect to mysql database
I know that this forum has a lot of answering about database in javafx but all results are converted to ObservableList
Thank you for all the answers.
FlightControllerTask.java
public class FlightControllerTask extends Task<LinkedList<Flight>>{
private final static int MAX=10000;
ArrayList<Airport> airportList=new ArrayList<>()
@Override
protected LinkedList<Flight> call() throws Exception {
for (int i = 0; i < MAX; i++) {
updateProgress(i, MAX);
Thread.sleep(5);
}
LinkedList<Flight> flightList = new LinkedList<>();
Connection c ;
c = DBConnector.connect();
String SQL = "SELECT flight.idflight, airport.nameAirport, airport.nameAirport, flight.departureTime FROM flight INNER JOIN airport";
ResultSet rs = c.createStatement().executeQuery(SQL);
while(rs.next()){
flightList.add(new Flight(rs.getInt("idflight"), rs.getString("flightFrom"), rs.getString("flightTo"), rs.getTime("departureTime")));
}
return flightList;
}
FlightControllerService
public class FlightControllerService extends Service<LinkedList<Flight>>{
@Override
protected Task<LinkedList<Flight>> createTask() {
return new FlightControllerTask();
}
}
MainController.java
final FlightControllerService service= new FlightControllerService();
ReadOnlyObjectProperty<LinkedList<Flight>> flightList =service.valueProperty();
flightList.get();