-
Notifications
You must be signed in to change notification settings - Fork 0
/
Doctor.java
54 lines (48 loc) · 1.95 KB
/
Doctor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package HospitalManagementSystem;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;
public class Doctor {
private Connection connection;
public Doctor(Connection connection){
this.connection = connection;
}
public void viewDoctors(){
String query = "select * from doctors";
try{
PreparedStatement preparedStatement = connection.prepareStatement(query);
ResultSet resultSet = preparedStatement.executeQuery();
System.out.println("Doctors: ");
System.out.println("+------------+--------------------+------------------+");
System.out.println("| Doctor Id | Name | Specialization |");
System.out.println("+------------+--------------------+------------------+");
while(resultSet.next()){
int id = resultSet.getInt("id");
String name = resultSet.getString("name");
String specialization = resultSet.getString("specialization");
System.out.printf("| %-10s | %-18s | %-16s |\n", id, name, specialization);
System.out.println("+------------+--------------------+------------------+");
}
}catch (SQLException e){
e.printStackTrace();
}
}
public boolean getDoctorById(int id){
String query = "SELECT * FROM doctors WHERE id = ?";
try{
PreparedStatement preparedStatement = connection.prepareStatement(query);
preparedStatement.setInt(1, id);
ResultSet resultSet = preparedStatement.executeQuery();
if(resultSet.next()){
return true;
}else{
return false;
}
}catch (SQLException e){
e.printStackTrace();
}
return false;
}
}