Skip to content

Commit

Permalink
Exported add list to external method
Browse files Browse the repository at this point in the history
  • Loading branch information
Nisheshg5 committed Jan 10, 2021
1 parent 97fc885 commit 9256227
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 31 deletions.
20 changes: 13 additions & 7 deletions src/hospital/services/DoctorSql.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import hospital.model.Doctor;
import hospital.model.GENDER;
Expand All @@ -14,18 +15,24 @@ public class DoctorSql {
/**
* Get all paients from the database.
*
* @return a {@link ResultSet} containing all paients from the database
* @return a {@link ArrayList} of type {@link Doctor} containing all doctors
* from the database
*/
public static ResultSet getDoctors() {
ResultSet resultSet = null;
public static ArrayList<Doctor> getDoctors() {
ArrayList<Doctor> doctors = new ArrayList<Doctor>();
try {
PreparedStatement statement = Main.conn
.prepareStatement("select id, name, age, gender, speciality, contact, address from doctor");
resultSet = statement.executeQuery();
ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
doctors.add(generateDoctor(resultSet));
}
return doctors;
} catch (SQLException e) {
e.printStackTrace();
}
return resultSet;

return null;
}

/**
Expand Down Expand Up @@ -123,8 +130,7 @@ public static int updateDoctor(Doctor doctor) {
public static String getIdOfLastDoctor() {
String id = "";
try {
PreparedStatement statement = Main.conn
.prepareStatement("SELECT id FROM doctor ORDER BY id DESC LIMIT 1;");
PreparedStatement statement = Main.conn.prepareStatement("SELECT id FROM doctor ORDER BY id DESC LIMIT 1;");
ResultSet resultSet = statement.executeQuery();
if (resultSet.next())
id = resultSet.getString(1);
Expand Down
17 changes: 12 additions & 5 deletions src/hospital/services/PatientSql.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import hospital.model.GENDER;
import hospital.model.GenerateGender;
Expand All @@ -14,18 +15,24 @@ public class PatientSql {
/**
* Get all paients from the database.
*
* @return a {@link ResultSet} containing all paients from the database
* @return a {@link ArrayList} of type {@link Patient} containing all patients
* from the database
*/
public static ResultSet getPatients() {
ResultSet resultSet = null;
public static ArrayList<Patient> getPatients() {
ArrayList<Patient> patients = new ArrayList<Patient>();
try {
PreparedStatement statement = Main.conn
.prepareStatement("select id, name, age, gender, contact, address from patient");
resultSet = statement.executeQuery();
ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
patients.add(generatePatient(resultSet));
}
return patients;
} catch (SQLException e) {
e.printStackTrace();
}
return resultSet;

return null;
}

/**
Expand Down
10 changes: 1 addition & 9 deletions src/hospital/ui/view/doctor/DoctorOverviewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,7 @@ public class DoctorOverviewController {
ResultSet resultSet = null;

public DoctorOverviewController() {
try {
resultSet = DoctorSql.getDoctors();
while (resultSet.next()) {
Doctor doctor = DoctorSql.generateDoctor(resultSet);
doctorList.add(doctor);
}
} catch (SQLException e) {
e.printStackTrace();
}
doctorList.addAll(DoctorSql.getDoctors());
}

@FXML
Expand Down
11 changes: 1 addition & 10 deletions src/hospital/ui/view/patient/PatientOverviewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;

import hospital.model.GENDER;
import hospital.model.Patient;
Expand Down Expand Up @@ -39,15 +38,7 @@ public class PatientOverviewController {
ResultSet resultSet = null;

public PatientOverviewController() {
try {
resultSet = PatientSql.getPatients();
while (resultSet.next()) {
Patient patient = PatientSql.generatePatient(resultSet);
patientList.add(patient);
}
} catch (SQLException e) {
e.printStackTrace();
}
patientList.addAll(PatientSql.getPatients());
}

@FXML
Expand Down

0 comments on commit 9256227

Please sign in to comment.