-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathUserDAO.java
More file actions
78 lines (70 loc) · 1.6 KB
/
UserDAO.java
File metadata and controls
78 lines (70 loc) · 1.6 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
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
// DAO Contains the DB Logic
// DAO Stands For Data Access Object
public class UserDAO {
public String register(UserDTO userDTO) throws SQLException, ClassNotFoundException{
CommonDAO commonDAO = CommonDAO.getObject();
Connection con=null;
PreparedStatement pstmt = null;
try{
con = commonDAO.getConnection();
if(con==null){
return StatusConstants.ERROR;
}
pstmt = con.prepareStatement(SQLConstants.REGISTER_SQL);
pstmt.setString(1, userDTO.getUserid());
pstmt.setString(2, userDTO.getPassword());
int recordEffected = pstmt.executeUpdate();
if(recordEffected>0){
return StatusConstants.SUCCESS;
}
else
{
return StatusConstants.FAIL;
}
}
finally{
if(pstmt!=null)
{
pstmt.close();
}
if(con!=null){
con.close();
}
}
}
public String login(UserDTO userDTO) throws ClassNotFoundException, SQLException{
CommonDAO commonDAO = CommonDAO.getObject();
Connection con=null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try{
con = commonDAO.getConnection();
if(con==null){
return StatusConstants.ERROR;
}
pstmt = con.prepareStatement(SQLConstants.LOGIN_SQL);
pstmt.setString(1, userDTO.getUserid());
pstmt.setString(2, userDTO.getPassword());
rs = pstmt.executeQuery();
if(rs.next()){
return StatusConstants.SUCCESS;
}
}
finally{
if(rs!=null){
rs.close();
}
if(pstmt!=null){
pstmt.close();
}
if(con!=null){
con.close();
}
}
return StatusConstants.FAIL;
}
}