-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoctors.java
60 lines (53 loc) · 1.7 KB
/
doctors.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
55
56
57
58
59
60
package JDBC.HospitalManagment;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Scanner;
public class doctors {
private Connection con;
public doctors(Connection con) {
this.con = con;
}
// methods
public void ViewDoctors()
{
String query="SELECT * FROM doctors;";
try{
PreparedStatement ps=con.prepareStatement(query);
ResultSet rs=ps.executeQuery();
System.out.println("Doctor Details...");
System.out.println("+-----------+----------------------------+--------------------------+");
System.out.println("| DoctorId | Name | Specialization |");
System.out.println("+-----------+----------------------------+--------------------------+");
while(rs.next())
{
int id=rs.getInt("id");
String name=rs.getString("name");
String specialization=rs.getString("specialization");
System.out.printf("|%-11s|%-28s|%-26s|\n",id,name,specialization);
System.out.println("+-----------+----------------------------+--------------------------+");
}
}catch(Exception e)
{
System.out.println(e.getMessage());
}
}
public boolean getDoctorbyid(int id)
{
String query="SELECT * FROM doctors WHERE ID=? ; ";
try {
PreparedStatement ps=con.prepareStatement(query);
ps.setInt(1, id);
ResultSet rs=ps.executeQuery();
if(rs.next())
{
return true;
}else{
return false;
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
return false;
}
}