-
Notifications
You must be signed in to change notification settings - Fork 1
/
Admin.java
161 lines (105 loc) · 4.77 KB
/
Admin.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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package business;
import java.sql.*;
/**
*
* @author Kevin
*/
public class Admin {
private String Admin_id;
private String firstName;
private String lastName;
private String email;
private String phoneNum;
public Admin() {
Admin_id="";
firstName="";
lastName="";
email="";
phoneNum="";
}
public Admin(String i, String fo, String ln, String em, String in ) {
Admin_id = i;
firstName = fo;
lastName=ln;
email=em;
phoneNum=in;
}
/*********************************************************************
*
* The selectDB class is used to select from database
*
*******************************************************************/
public void selectDB(String i) {
Admin_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 Admin where Admin_id='"+getAdmin_id()+"'";
//Process ResultSet
System.out.println(sql);
ResultSet rs = stmt.executeQuery(sql);
rs.next();
setfirstName(rs.getString(1));
setlastName(rs.getString(2));
setemail(rs.getString(3));
setphoneNum(rs.getString(4));
}
catch(Exception se) {
System.out.println(se);
}
} //end selectDB()
public void insertDB(String ap, String pd, String dt, String pc, String ph){
setAdmin_id(ap);
setfirstName(pd);
setlastName(dt);
setemail(pc);
setphoneNum(ph);
try{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection con = DriverManager.getConnection("jdbc:ucanaccess://C:/Users/Kevin/Downloads/ChiropractorOfficeMDB.accdb");
Statement stmt = con.createStatement();
String sql = "Insert into Admin values('"+ getAdmin_id() +"','"+getfirstName()+"', '"+getlastName()+"','"+getemail()+"', '"+getphoneNum()+"')";
System.out.println(sql);
int n = stmt.executeUpdate(sql);
if (n==1)
System.out.println("INSERT Successful!!!");
else
System.out.println("INSERT FAILED***********");
con.close();
}
catch(Exception e1){
System.out.println(e1);
}
}//end insertDB()
public String getAdmin_id() { return Admin_id; }
public void setAdmin_id(String i) { Admin_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 getemail() { return email; }
public void setemail(String em) { email=em; }
public String getphoneNum() { return phoneNum; }
public void setphoneNum(String in) { phoneNum=in; }
public void display() {
System.out.println("ID = "+ Admin_id);
System.out.println("Firat Name = "+ firstName);
System.out.println("Last Name = "+ lastName);
System.out.println("Email = "+ email);
System.out.println("Phone number = "+ phoneNum);
}
public static void main(String args[]) {
// Testing Database methods
Admin a1;
a1 = new Admin();
a1.selectDB("A100");
a1.display();
}
}