-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPatients.java
163 lines (142 loc) · 5.67 KB
/
Patients.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package Business;
//Java 111 Kevin Lyons
import java.sql.*;
/*********************************************************************
*
* The Patients class is used to hold Patients
*
*******************************************************************/
public class Patients {
private String Patient_id;
private String firstName;
private String lastName;
private String address;
private String city;
private String state;
private String zip;
private String email;
private String ins_co;
//============== Overloading Constructors ==================================
//Constructor with no arguments
public Patients() {
Patient_id="";
firstName="";
lastName="";
address="";
city="";
state="";
zip="";
email="";
ins_co="";
}
//Constructor with arguments
public Patients(String i, String fo, String ln, String p, String ci, String st, String zp, String em, String in ) {
Patient_id = i;
firstName = fo;
lastName=ln;
address=p;
city=ci;
state=st;
zip=zp;
email=em;
ins_co=in;
}
/*********************************************************************
*
* The selectDB class is used to select from database
*
*******************************************************************/
public void selectDB(String i) {
Patient_id=i;
try { //Load DB Driver
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection con1 = DriverManager.getConnection("jdbc:ucanaccess://C:/Users/Kevin/Downloads/ChiropractorOfficeMDB.accdb");
//Execute SQL Statement
Statement stmt =con1.createStatement();
String sql = "Select * from Patients where Patient_id='"+getPatient_id()+"'";
//Process ResultSet
System.out.println(sql);
ResultSet rs = stmt.executeQuery(sql);
rs.next();
setfirstName(rs.getString(1));
setlastName(rs.getString(2));
setaddress(rs.getString(3));
setcity(rs.getString(4));
setstate(rs.getString(5));
setzip(rs.getString(6));
setemail(rs.getString(7));
setins_co(rs.getString(8));
}catch(Exception se) {
System.out.println(se);
}
} //end selectDB()
// ++++++++++ DB Behaviors +++++++++++++
/************************************************************************
* selectDB() gets the patient data and information from the Database
*************************************************************************/
public void updateDB(){
try{
//Loading the driver
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection con = DriverManager.getConnection("jdbc:ucanaccess://C:/Users/Kevin/Downloads/ChiropractorOfficeMDB.accdb");
System.out.println("Database connected and ready to be updated");
Statement stmt = con.createStatement();
String sql = "UPDATE Patients SET firstname = '"+ getfirstName() +"',"
+ "lastName = '"+ getlastName() +"',"
+ "address = '"+ getaddress() +"',"
+ "city = '"+ getcity() +"',"
+ "state = '"+ getstate() +"',"
+ "zip = '"+ getzip() +"',"
+ "email = '"+ getemail() +"',"
+ "ins_co = '"+ getins_co() +"'"
+ " WHERE Patient_id ='"+ getPatient_id() +"'" ;
int n = stmt.executeUpdate(sql);
// Checking if the code has been executed
if(n == 1){
System.out.println("Success !!! ");
}
else{
System.out.println("Failed !!!");
}
}catch(Exception ex){
ex.printStackTrace();
}
}//end of updateDB
public String getPatient_id() { return Patient_id; }
public void setPatient_id(String i) { Patient_id=i; }
public String getfirstName() { return firstName; }
public void setfirstName(String fo) { firstName=fo; }
public String getlastName() { return lastName; }
public void setlastName(String ln) { lastName=ln; }
public String getaddress() { return address; }
public void setaddress(String p) { address=p; }
public String getcity() { return city; }
public void setcity(String ci) { city=ci; }
public String getstate() { return state; }
public void setstate(String st) { state=st; }
public String getzip() { return zip; }
public void setzip(String zp) {zip=zp; }
public String getemail() { return email; }
public void setemail(String em) { email=em; }
public String getins_co() { return ins_co; }
public void setins_co(String in) { ins_co=in; }
public void display() {
System.out.println("ID = "+ Patient_id);
System.out.println("Firat Name = "+ firstName);
System.out.println("Last Name = "+ lastName);
System.out.println("Address = "+ address);
System.out.println("City = "+ city);
System.out.println("State = "+ state);
System.out.println("Zip = "+ zip);
System.out.println("Email = "+ email);
System.out.println("Ins_Co = "+ ins_co);
}
// Testing Class
public static void main(String args[]) {
// Testing Database methods
Patients p1;
p1 = new Patients();
p1.selectDB("P201");
p1.display();
}
}