Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. public void loadFlightFromDB()
  2. {
  3. try
  4. {
  5. Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
  6. Connection conn = DriverManager.getConnection("jdbc:ucanaccess://H:\\YEAR 2\\OO PROGRAMMING (JAMES)\\ScotiaAirlines\\Airline.accdb");
  7. Statement stmt = conn.createStatement();
  8. ResultSet rs = stmt.executeQuery("SELECT * FROM Flight");
  9.  
  10. while(rs.next())
  11. {
  12. String flightNumber = rs.getString(1);
  13. String departure = rs.getString(2);
  14. String arrival = rs.getString(3);
  15. int rows = rs.getInt(4);
  16. int columns = rs.getString(5).charAt(0);
  17.  
  18. Flight loadedFlight = new Flight(columns, rows);
  19. AddFlight(loadedFlight);
  20. }
  21. }
  22. catch(Exception ex)
  23. {
  24. String massage = ex.getMessage();
  25. }
  26. }
  27.  
  28. public void saveFlightsToDB()
  29. {
  30. try
  31. {
  32. Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
  33. Connection conn = DriverManager.getConnection("jdbc:ucanaccess://H:\\YEAR 2\\OO PROGRAMMING (JAMES)\\ScotiaAirlines\\Airline.accdb");
  34. Statement stmt = conn.createStatement();
  35.  
  36. for(Map.Entry<String,Flight> f : people.entrySet())
  37. {
  38. Flight actualFlight = f.getValue();
  39. stmt.executeUpdate("INSERT INTO People VALUES ('" + actualFlight.getFlightNumber() + "','" + actualFlight.getDeparture() + "','"
  40. + actualFlight.getArrival() + "','" + actualFlight.getRows() + "','" + actualFlight.getColumns() + "')");
  41. }
  42. }
  43. catch(Exception ex)
  44. {
  45. String message = ex.getMessage();
  46. }
  47. }
  48.  
  49. public void clearFlightsFromDB()
  50. {
  51. try
  52. {
  53. Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
  54. Connection conn = DriverManager.getConnection("jdbc:ucanaccess://H:\\YEAR 2\\OO PROGRAMMING (JAMES)\\ScotiaAirlines\\Airline.accdb");
  55. Statement stmt = conn.createStatement();
  56. stmt.executeUpdate("DELETE * FROM Flights");
  57. }
  58. catch(Exception ex)
  59. {
  60. String message = ex.getMessage();
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement