-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployeeDao.java
More file actions
88 lines (60 loc) · 2.17 KB
/
EmployeeDao.java
File metadata and controls
88 lines (60 loc) · 2.17 KB
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
package com.Database;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
public class EmployeeDao {
Connection con = JDBCConnection.getConnection();
public String getConnection(Employee employee) {
try {
PreparedStatement pst = con.prepareStatement("insert into employeedetails values(?,?,?,?,?,?)");
pst.setString(1, employee.getName());
pst.setString(2, employee.getEmail());
pst.setString(3, employee.getPassword());
pst.setString(4, employee.getDepartment());
pst.setString(5, employee.getGender());
pst.setString(6, employee.getCity());
pst.execute();
}catch(Exception e) {
System.out.println(e.getMessage());
}
return "Employee Registration Successfull";
}
public Employee loginEmployee(String email, String password) {
Employee employee = null;
try {
PreparedStatement pst = con.prepareStatement("select * from employeedetails where email=? and password=?");
pst.setString(1, email);
pst.setString(2, password);
ResultSet rs = pst.executeQuery();
while(rs.next()) {
String takenemail = rs.getString("email");
String takenpassword = rs.getString("password");
employee = new Employee(takenemail, takenpassword);
}
}catch(Exception e) {
System.out.println(e.getMessage());
}
return employee;
}
public ArrayList<Employee> getAllemployees() {
ArrayList<Employee> employees = new ArrayList<Employee>();
try {
PreparedStatement pst = con.prepareStatement("select * from employeedetails");
ResultSet rs = pst.executeQuery();
while(rs.next()) {
String name = rs.getString("name");
String email = rs.getString("email");
String password = rs.getString("password");
String department = rs.getString("department");
String gender = rs.getString("gender");
String city = rs.getString("city");
Employee employee = new Employee(name, email, password, department, gender, city);
employees.add(employee);
}
}catch(Exception e) {
System.out.println(e.getMessage());
}
return employees;
}
}