Advertisement
Guest User

Untitled

a guest
Sep 16th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.04 KB | None | 0 0
  1. package model;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import java.util.Date;
  9. import javafx.collections.FXCollections;
  10. import javafx.collections.ObservableList;
  11.  
  12. public class Context {
  13.  
  14. /*
  15. * This Singleton object keeps track of all the data for the application
  16. * Could be better but no time to optimize and shit
  17. */
  18.  
  19. private final static Context instance = new Context();
  20. private static ObservableList<Patient> patientData = FXCollections.observableArrayList();
  21. private static ObservableList<Measurement> measurementData = FXCollections.observableArrayList();
  22. private static ObservableList<Report> reportData = FXCollections.observableArrayList();
  23. private static ObservableList<Garment> garmentData = FXCollections.observableArrayList();
  24.  
  25.  
  26.  
  27. public static Context getInstance(){
  28. return instance;
  29. }
  30.  
  31. public static ObservableList<Patient> getPatientData(){
  32. return patientData;
  33. }
  34.  
  35.  
  36. public static ObservableList<Report> getReportData(){
  37. return reportData;
  38. }
  39.  
  40.  
  41. public static ObservableList<Measurement> getMeasurementData(){
  42. return measurementData;
  43. }
  44.  
  45. public static ObservableList<Garment> getGarmentData(){
  46. return garmentData;
  47. }
  48.  
  49. public static void setPatientData(ObservableList<Patient> incoming){
  50. patientData = incoming;
  51. }
  52.  
  53.  
  54. public static void setMeasurementData(ObservableList<Measurement> incoming){
  55. measurementData = incoming;
  56. }
  57.  
  58. public static void setReportData(ObservableList<Report> incoming){
  59. reportData = incoming;
  60. }
  61.  
  62. public static void setGarmentData(ObservableList<Garment> incoming){
  63. garmentData = incoming;
  64. }
  65.  
  66. /*
  67. * Helper method to add new patients to the database and update the application
  68. */
  69.  
  70. public static void addPatients(String firstName, String lastName, String dob, String gender, String number, String email){
  71. PreparedStatement preparedStatement = null;
  72. Connection connection = null;
  73.  
  74. try {
  75.  
  76. String connectionString = "jdbc:mysql://188.166.215.160:3306/isys3400?useSSL=false";
  77. connection = DriverManager.getConnection(connectionString, "application", "@ISYS3400project");
  78.  
  79. preparedStatement = connection.prepareStatement(
  80. "INSERT INTO Patient (registered, first_name, last_name, dob, gender, number, email) "
  81. + "VALUES (now(),?,?,?,?,?,?)");
  82.  
  83. preparedStatement.setString(1, firstName);
  84. preparedStatement.setString(2, lastName);
  85. preparedStatement.setString(3, dob);
  86. preparedStatement.setString(4, gender);
  87. preparedStatement.setString(5, number);
  88. preparedStatement.setString(6, email);
  89.  
  90. preparedStatement.executeUpdate();
  91.  
  92. patientData.clear();
  93. loadPatients();
  94.  
  95. } catch (SQLException e) {
  96. System.out.println("SQLException: " + e.getMessage());
  97. System.out.println("SQLState: " + e.getSQLState());
  98. } finally {
  99.  
  100. try {
  101. if(preparedStatement != null){
  102. preparedStatement.close();
  103. }
  104.  
  105. if(connection != null){
  106. connection.close();
  107. }
  108.  
  109. } catch (SQLException e){
  110. System.out.println("SQLException: " + e.getMessage());
  111. System.out.println("SQLState: " + e.getSQLState());
  112. }
  113.  
  114. }
  115. }
  116.  
  117. public static void addMeasurement(String type, String side, String bioimpedance, String m1, String m2, String m3,
  118. String m4, String m5, int patient_id){
  119. PreparedStatement preparedStatement = null;
  120. Connection connection = null;
  121.  
  122. try {
  123.  
  124. String connectionString = "jdbc:mysql://188.166.215.160:3306/isys3400?useSSL=false";
  125. connection = DriverManager.getConnection(connectionString, "application", "@ISYS3400project");
  126.  
  127. preparedStatement = connection.prepareStatement(
  128. "INSERT INTO Measurement (date, type, side, bioimpedance, first, second, third, fourth, fifth, patient_id) "
  129. + "VALUES (now(),?,?,?,?,?,?,?,?,?)");
  130. preparedStatement.setString(1, type);
  131. preparedStatement.setString(2, side);
  132. preparedStatement.setString(3, bioimpedance);
  133. preparedStatement.setString(4, m1);
  134. preparedStatement.setString(5, m2);
  135. preparedStatement.setString(6, m3);
  136. preparedStatement.setString(7, m4);
  137. preparedStatement.setString(8, m5);
  138. preparedStatement.setInt(9, patient_id);
  139. preparedStatement.executeUpdate();
  140.  
  141. measurementData.clear();
  142. loadMeasurements();
  143.  
  144. } catch (SQLException e) {
  145. System.out.println("SQLException: " + e.getMessage());
  146. System.out.println("SQLState: " + e.getSQLState());
  147. } finally {
  148.  
  149. try {
  150. if(preparedStatement != null){
  151. preparedStatement.close();
  152. }
  153.  
  154. if(connection != null){
  155. connection.close();
  156. }
  157.  
  158. } catch (SQLException e){
  159. System.out.println("SQLException: " + e.getMessage());
  160. System.out.println("SQLState: " + e.getSQLState());
  161. }
  162.  
  163. }
  164. }
  165.  
  166. public static void addGarment(String side, String a, String b, String c, String d,
  167. String e, String f, String g, int patient_id){
  168. PreparedStatement preparedStatement = null;
  169. Connection connection = null;
  170.  
  171. try {
  172.  
  173. String connectionString = "jdbc:mysql://188.166.215.160:3306/isys3400?useSSL=false";
  174. connection = DriverManager.getConnection(connectionString, "application", "@ISYS3400project");
  175.  
  176. preparedStatement = connection.prepareStatement(
  177. "INSERT INTO Garment (date, side, a, b, c, d, e, f, g, patient_id) "
  178. + "VALUES (now(),?,?,?,?,?,?,?,?,?)");
  179. preparedStatement.setString(1, side);
  180. preparedStatement.setString(2, a);
  181. preparedStatement.setString(3, b);
  182. preparedStatement.setString(4, c);
  183. preparedStatement.setString(5, d);
  184. preparedStatement.setString(6, e);
  185. preparedStatement.setString(7, f);
  186. preparedStatement.setString(8, g);
  187. preparedStatement.setInt(9, patient_id);
  188. preparedStatement.executeUpdate();
  189.  
  190. garmentData.clear();
  191. loadGarments();
  192.  
  193. } catch (SQLException x) {
  194. System.out.println("SQLException: " + x.getMessage());
  195. System.out.println("SQLState: " + x.getSQLState());
  196. } finally {
  197.  
  198. try {
  199. if(preparedStatement != null){
  200. preparedStatement.close();
  201. }
  202.  
  203. if(connection != null){
  204. connection.close();
  205. }
  206.  
  207. } catch (SQLException x){
  208. System.out.println("SQLException: " + x.getMessage());
  209. System.out.println("SQLState: " + x.getSQLState());
  210. }
  211.  
  212. }
  213. }
  214.  
  215.  
  216.  
  217. /*
  218. * Helper method to commit updates of patient data to the database and update the application
  219. */
  220.  
  221. public static void commitPatients(String toCommit, int patient_id, int position){
  222. PreparedStatement preparedStatement = null;
  223. Connection connection = null;
  224.  
  225. try {
  226.  
  227. String connectionString = "jdbc:mysql://188.166.215.160:3306/isys3400?useSSL=false";
  228. connection = DriverManager.getConnection(connectionString, "application", "@ISYS3400project");
  229.  
  230. switch(position){
  231. case 3: // first name
  232. preparedStatement = connection.prepareStatement("UPDATE Patient SET first_name = ? WHERE id = ?");
  233. for(Patient p : patientData){
  234. if(p.getIDProperty().get() == patient_id){
  235. p.getFirstNameProperty().set(toCommit);
  236. }
  237. }
  238. break;
  239. case 4: // last name
  240. preparedStatement = connection.prepareStatement("UPDATE Patient SET first_name = ? WHERE id = ?");
  241. for(Patient p : patientData){
  242. if(p.getIDProperty().get() == patient_id){
  243. p.getLastNameProperty().set(toCommit);
  244. }
  245. }
  246. break;
  247. case 5: // dob
  248. preparedStatement = connection.prepareStatement("UPDATE Patient SET dob = ? WHERE id = ?");
  249. for(Patient p : patientData){
  250. if(p.getIDProperty().get() == patient_id){
  251. p.getDOBProperty().set(toCommit);
  252. }
  253. }
  254. break;
  255. case 6: // gender
  256. preparedStatement = connection.prepareStatement("UPDATE Patient SET gender = ? WHERE id = ?");
  257. for(Patient p : patientData){
  258. if(p.getIDProperty().get() == patient_id){
  259. p.getGenderProperty().set(toCommit);
  260. }
  261. }
  262. break;
  263. case 7: // number
  264. preparedStatement = connection.prepareStatement("UPDATE Patient SET number = ? WHERE id = ?");
  265. for(Patient p : patientData){
  266. if(p.getIDProperty().get() == patient_id){
  267. p.getNumberProperty().set(toCommit);
  268. }
  269. }
  270. break;
  271. case 8: // email
  272. preparedStatement = connection.prepareStatement("UPDATE Patient SET email = ? WHERE id = ?");
  273. for(Patient p : patientData){
  274. if(p.getIDProperty().get() == patient_id){
  275. p.getEmailProperty().set(toCommit);
  276. }
  277. }
  278. break;
  279. }
  280.  
  281. preparedStatement.setString(1, toCommit);
  282. preparedStatement.setInt(2, patient_id);
  283. preparedStatement.executeUpdate();
  284.  
  285. } catch (SQLException e) {
  286. System.out.println("SQLException: " + e.getMessage());
  287. System.out.println("SQLState: " + e.getSQLState());
  288. } finally {
  289.  
  290. try {
  291. if(preparedStatement != null){
  292. preparedStatement.close();
  293. }
  294.  
  295. if(connection != null){
  296. connection.close();
  297. }
  298.  
  299. } catch (SQLException e){
  300. System.out.println("SQLException: " + e.getMessage());
  301. System.out.println("SQLState: " + e.getSQLState());
  302. }
  303. }
  304. }
  305.  
  306. public static void commitMeasurements(String toCommit, int measurement_id, int position){
  307. PreparedStatement preparedStatement = null;
  308. Connection connection = null;
  309.  
  310. // probably a better way to do this.
  311.  
  312. try {
  313.  
  314. String connectionString = "jdbc:mysql://188.166.215.160:3306/isys3400?useSSL=false";
  315. connection = DriverManager.getConnection(connectionString, "application", "@ISYS3400project");
  316.  
  317. switch(position){
  318. case 3: // type
  319. preparedStatement = connection.prepareStatement("UPDATE Measurement SET type = ? WHERE id = ?");
  320. for(Measurement m : measurementData){
  321. if(m.getIDProperty().get() == measurement_id){
  322. m.getTypeProperty().set(toCommit);
  323. }
  324. }
  325. preparedStatement.setString(1, toCommit);
  326. break;
  327. case 4: // side
  328. preparedStatement = connection.prepareStatement("UPDATE Measurement SET side = ? WHERE id = ?");
  329. for(Measurement m : measurementData){
  330. if(m.getIDProperty().get() == measurement_id){
  331. m.getSideProperty().set(toCommit);
  332. }
  333. }
  334. preparedStatement.setString(1, toCommit);
  335. break;
  336. case 5: // bioimpedance
  337. preparedStatement = connection.prepareStatement("UPDATE Measurement SET bioimpedance = ? WHERE id = ?");
  338. for(Measurement m : measurementData){
  339. if(m.getIDProperty().get() == measurement_id){
  340. m.getBioimpedanceProperty().set(Double.parseDouble(toCommit));
  341. }
  342. }
  343. preparedStatement.setDouble(1, Double.parseDouble(toCommit));
  344. break;
  345. case 6: // first
  346. preparedStatement = connection.prepareStatement("UPDATE Measurement SET first = ? WHERE id = ?");
  347. for(Measurement m : measurementData){
  348. if(m.getIDProperty().get() == measurement_id){
  349. m.getFirstProperty().set(Double.parseDouble(toCommit));
  350. }
  351. }
  352. preparedStatement.setDouble(1, Double.parseDouble(toCommit));
  353. break;
  354. case 7: // second
  355. preparedStatement = connection.prepareStatement("UPDATE Measurement SET second = ? WHERE id = ?");
  356. for(Measurement m : measurementData){
  357. if(m.getIDProperty().get() == measurement_id){
  358. m.getSecondProperty().set(Double.parseDouble(toCommit));
  359. }
  360. }
  361. preparedStatement.setDouble(1, Double.parseDouble(toCommit));
  362. break;
  363. case 8: // third
  364. preparedStatement = connection.prepareStatement("UPDATE Measurement SET third = ? WHERE id = ?");
  365. for(Measurement m : measurementData){
  366. if(m.getIDProperty().get() == measurement_id){
  367. m.getThirdProperty().set(Double.parseDouble(toCommit));
  368. }
  369. }
  370. preparedStatement.setDouble(1, Double.parseDouble(toCommit));
  371. break;
  372. case 9: // fourth
  373. preparedStatement = connection.prepareStatement("UPDATE Measurement SET fourth = ? WHERE id = ?");
  374. for(Measurement m : measurementData){
  375. if(m.getIDProperty().get() == measurement_id){
  376. m.getFourthProperty().set(Double.parseDouble(toCommit));
  377. }
  378. }
  379. preparedStatement.setDouble(1, Double.parseDouble(toCommit));
  380. break;
  381. case 10: // fifth
  382. preparedStatement = connection.prepareStatement("UPDATE Measurement SET fifth = ? WHERE id = ?");
  383. for(Measurement m : measurementData){
  384. if(m.getIDProperty().get() == measurement_id){
  385. m.getFifthProperty().set(Double.parseDouble(toCommit));
  386. }
  387. }
  388. preparedStatement.setDouble(1, Double.parseDouble(toCommit));
  389. break;
  390. }
  391.  
  392. preparedStatement.setInt(2, measurement_id);
  393. preparedStatement.executeUpdate();
  394.  
  395. } catch (SQLException e) {
  396. System.out.println("SQLException: " + e.getMessage());
  397. System.out.println("SQLState: " + e.getSQLState());
  398. } finally {
  399.  
  400. try {
  401. if(preparedStatement != null){
  402. preparedStatement.close();
  403. }
  404.  
  405. if(connection != null){
  406. connection.close();
  407. }
  408.  
  409. } catch (SQLException e){
  410. System.out.println("SQLException: " + e.getMessage());
  411. System.out.println("SQLState: " + e.getSQLState());
  412. }
  413. }
  414. }
  415.  
  416. public static void commitGarments(String toCommit, int garment_id, int position){
  417. PreparedStatement preparedStatement = null;
  418. Connection connection = null;
  419.  
  420. // probably a better way to do this.
  421.  
  422. try {
  423.  
  424. String connectionString = "jdbc:mysql://188.166.215.160:3306/isys3400?useSSL=false";
  425. connection = DriverManager.getConnection(connectionString, "application", "@ISYS3400project");
  426.  
  427. switch(position){
  428. case 3: // side
  429. preparedStatement = connection.prepareStatement("UPDATE Garment SET side = ? WHERE id = ?");
  430. for(Garment g : garmentData){
  431. if(g.getIDProperty().get() == garment_id){
  432. g.getSideProperty().set(toCommit);
  433. }
  434. }
  435. preparedStatement.setString(1, toCommit);
  436. break;
  437. case 4: // a
  438. preparedStatement = connection.prepareStatement("UPDATE Garment SET a = ? WHERE id = ?");
  439. for(Garment g : garmentData){
  440. if(g.getIDProperty().get() == garment_id){
  441. g.getAProperty().set(Double.parseDouble(toCommit));
  442. }
  443. }
  444. preparedStatement.setDouble(1, Double.parseDouble(toCommit));
  445. break;
  446. case 5: // b
  447. preparedStatement = connection.prepareStatement("UPDATE Garment SET b = ? WHERE id = ?");
  448. for(Garment g : garmentData){
  449. if(g.getIDProperty().get() == garment_id){
  450. g.getBProperty().set(Double.parseDouble(toCommit));
  451. }
  452. }
  453. preparedStatement.setDouble(1, Double.parseDouble(toCommit));
  454. break;
  455. case 6: // c
  456. preparedStatement = connection.prepareStatement("UPDATE Garment SET c = ? WHERE id = ?");
  457. for(Garment g : garmentData){
  458. if(g.getIDProperty().get() == garment_id){
  459. g.getCProperty().set(Double.parseDouble(toCommit));
  460. }
  461. }
  462. preparedStatement.setDouble(1, Double.parseDouble(toCommit));
  463. break;
  464. case 7: // d
  465. preparedStatement = connection.prepareStatement("UPDATE Garment SET d = ? WHERE id = ?");
  466. for(Garment g : garmentData){
  467. if(g.getIDProperty().get() == garment_id){
  468. g.getDProperty().set(Double.parseDouble(toCommit));
  469. }
  470. }
  471. preparedStatement.setDouble(1, Double.parseDouble(toCommit));
  472. break;
  473. case 8: // e
  474. preparedStatement = connection.prepareStatement("UPDATE Garment SET e = ? WHERE id = ?");
  475. for(Garment g : garmentData){
  476. if(g.getIDProperty().get() == garment_id){
  477. g.getEProperty().set(Double.parseDouble(toCommit));
  478. }
  479. }
  480. preparedStatement.setDouble(1, Double.parseDouble(toCommit));
  481. break;
  482. case 9: // f
  483. preparedStatement = connection.prepareStatement("UPDATE Garment SET f = ? WHERE id = ?");
  484. for(Garment g : garmentData){
  485. if(g.getIDProperty().get() == garment_id){
  486. g.getFProperty().set(Double.parseDouble(toCommit));
  487. }
  488. }
  489. preparedStatement.setDouble(1, Double.parseDouble(toCommit));
  490. break;
  491. case 10: // g
  492. preparedStatement = connection.prepareStatement("UPDATE Garment SET g = ? WHERE id = ?");
  493. for(Garment g : garmentData){
  494. if(g.getIDProperty().get() == garment_id){
  495. g.getGProperty().set(Double.parseDouble(toCommit));
  496. }
  497. }
  498. preparedStatement.setDouble(1, Double.parseDouble(toCommit));
  499. break;
  500. }
  501.  
  502. preparedStatement.setInt(2, garment_id);
  503. preparedStatement.executeUpdate();
  504.  
  505. } catch (SQLException e) {
  506. System.out.println("SQLException: " + e.getMessage());
  507. System.out.println("SQLState: " + e.getSQLState());
  508. } finally {
  509.  
  510. try {
  511. if(preparedStatement != null){
  512. preparedStatement.close();
  513. }
  514.  
  515. if(connection != null){
  516. connection.close();
  517. }
  518.  
  519. } catch (SQLException e){
  520. System.out.println("SQLException: " + e.getMessage());
  521. System.out.println("SQLState: " + e.getSQLState());
  522. }
  523. }
  524. }
  525.  
  526. public static void commitReport(String title, String content, int report_id){
  527. PreparedStatement preparedStatement = null;
  528. Connection connection = null;
  529.  
  530. try {
  531.  
  532. String connectionString = "jdbc:mysql://188.166.215.160:3306/isys3400?useSSL=false";
  533. connection = DriverManager.getConnection(connectionString, "application", "@ISYS3400project");
  534.  
  535. preparedStatement = connection.prepareStatement("UPDATE Report SET title = ?, content = ? WHERE id = ?");
  536. for(Report r : reportData){
  537. if(r.getIDProperty().get() == report_id){
  538. r.getTitleProperty().set(title);
  539. r.getContentProperty().set(content);
  540. }
  541. }
  542. preparedStatement.setString(1, title);
  543. preparedStatement.setString(2, content);
  544. preparedStatement.setInt(3, report_id);
  545. preparedStatement.executeUpdate();
  546.  
  547. } catch (SQLException e) {
  548. System.out.println("SQLException: " + e.getMessage());
  549. System.out.println("SQLState: " + e.getSQLState());
  550. } finally {
  551.  
  552. try {
  553. if(preparedStatement != null){
  554. preparedStatement.close();
  555. }
  556.  
  557. if(connection != null){
  558. connection.close();
  559. }
  560.  
  561. } catch (SQLException e){
  562. System.out.println("SQLException: " + e.getMessage());
  563. System.out.println("SQLState: " + e.getSQLState());
  564. }
  565. }
  566. }
  567.  
  568. public static void loadPatients(){
  569. try {
  570.  
  571. String connectionString = "jdbc:mysql://188.166.215.160:3306/isys3400?useSSL=false";
  572. Connection connection = DriverManager.getConnection(connectionString, "application", "@ISYS3400project");
  573.  
  574. PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM Patient");
  575. ResultSet rs = preparedStatement.executeQuery();
  576.  
  577. ObservableList<Patient> incomingData = FXCollections.observableArrayList();
  578.  
  579. while (rs.next()) {
  580.  
  581. int id = rs.getInt(1);
  582. Date date = rs.getDate(2);
  583. String firstName = rs.getString(3);
  584. String lastName = rs.getString(4);
  585. String dob = rs.getString(5);
  586. String gender = rs.getString(6);
  587. String number = rs.getString(7);
  588. String email = rs.getString(8);
  589.  
  590. incomingData.add(new Patient(id, date, firstName, lastName, dob, gender, number, email));
  591.  
  592. }
  593.  
  594. Context.getInstance();
  595. Context.setPatientData(incomingData);
  596.  
  597. } catch (SQLException e) {
  598. System.out.println("SQLException: " + e.getMessage());
  599. System.out.println("SQLState: " + e.getSQLState());
  600. }
  601. }
  602.  
  603. public static void loadMeasurements(){
  604.  
  605. try {
  606.  
  607. String connectionString = "jdbc:mysql://188.166.215.160:3306/isys3400?useSSL=false";
  608. Connection connection = DriverManager.getConnection(connectionString, "application", "@ISYS3400project");
  609.  
  610. PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM Measurement");
  611. ResultSet rs = preparedStatement.executeQuery();
  612.  
  613. ObservableList<Measurement> incomingData = FXCollections.observableArrayList();
  614.  
  615. while (rs.next()) {
  616.  
  617. int id = rs.getInt(1);
  618. Date date = rs.getDate(2);
  619. String type = rs.getString(3);
  620. String side = rs.getString(4);
  621. double bioimpedance = rs.getDouble(5);
  622. double first = rs.getDouble(6);
  623. double second = rs.getDouble(7);
  624. double third = rs.getDouble(8);
  625. double fourth = rs.getDouble(9);
  626. double fifth = rs.getDouble(10);
  627. int patient_id = rs.getInt(11);
  628.  
  629. incomingData.add(new Measurement(id, date, type, side, bioimpedance, first, second, third, fourth, fifth, patient_id));
  630.  
  631. }
  632.  
  633. Context.getInstance();
  634. Context.setMeasurementData(incomingData);
  635.  
  636. } catch (SQLException e) {
  637. System.out.println("SQLException: " + e.getMessage());
  638. System.out.println("SQLState: " + e.getSQLState());
  639. }
  640.  
  641. }
  642.  
  643. public static void loadReports(){
  644.  
  645. try {
  646.  
  647. String connectionString = "jdbc:mysql://188.166.215.160:3306/isys3400?useSSL=false";
  648. Connection connection = DriverManager.getConnection(connectionString, "application", "@ISYS3400project");
  649.  
  650. PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM Report");
  651. ResultSet rs = preparedStatement.executeQuery();
  652.  
  653. ObservableList<Report> incomingData = FXCollections.observableArrayList();
  654.  
  655. while (rs.next()) {
  656.  
  657. int id = rs.getInt(1);
  658. Date date = rs.getDate(2);
  659. String title = rs.getString(3);
  660. String content = rs.getString(4);
  661. int patient_id = rs.getInt(5);
  662. incomingData.add(new Report(id, date, title, content, patient_id));
  663.  
  664.  
  665. }
  666.  
  667. Context.getInstance();
  668. Context.setReportData(incomingData);
  669.  
  670. } catch (SQLException e) {
  671. System.out.println("SQLException: " + e.getMessage());
  672. System.out.println("SQLState: " + e.getSQLState());
  673. }
  674.  
  675. }
  676.  
  677. public static void loadGarments(){
  678.  
  679. try {
  680.  
  681. String connectionString = "jdbc:mysql://188.166.215.160:3306/isys3400?useSSL=false";
  682. Connection connection = DriverManager.getConnection(connectionString, "application", "@ISYS3400project");
  683.  
  684. PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM Garment");
  685. ResultSet rs = preparedStatement.executeQuery();
  686.  
  687. ObservableList<Garment> incomingData = FXCollections.observableArrayList();
  688.  
  689. while (rs.next()) {
  690.  
  691. int id = rs.getInt(1);
  692. Date date = rs.getDate(2);
  693. String side = rs.getString(3);
  694. double a = rs.getDouble(4);
  695. double b = rs.getDouble(5);
  696. double c = rs.getDouble(6);
  697. double d = rs.getDouble(7);
  698. double e = rs.getDouble(8);
  699. double f = rs.getDouble(9);
  700. double g = rs.getDouble(10);
  701. int patient_id = rs.getInt(11);
  702.  
  703. incomingData.add(new Garment(id, date, side, a, b, c, d, e, f, g, patient_id));
  704.  
  705. }
  706.  
  707. Context.getInstance();
  708. Context.setGarmentData(incomingData);
  709.  
  710. } catch (SQLException e) {
  711. System.out.println("SQLException: " + e.getMessage());
  712. System.out.println("SQLState: " + e.getSQLState());
  713. }
  714.  
  715. }
  716.  
  717.  
  718.  
  719. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement