728x90
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
|
package magic.member;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
public class MemberDBBean {
private static MemberDBBean md = new MemberDBBean();
public static MemberDBBean getInstance() {
return md;
//getInstance메소드 호출하면 바로 객체로 받을 수 있음
}
public Connection getConnection() throws Exception {
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/oracle");
return ds.getConnection();
// Connection con = ds.getConnection();
// return con;
//이미 커넥션으로 받았기 때문에 커넥션 객체 따로 생성해서 받을 필요 없음
}
public int insertMember(MemberBean member) throws Exception{
// StringBuffer insertQuery = new StringBuffer();
// insertQuery.append("insert into MEMBERT values(?,?,?,?,?,?)");
String insertQuery = "insert into MEMBERT values(?,?,?,?,?,?)";
Connection con = null;
PreparedStatement ps = null;
// ResultSet rs = null;
int re = -1;
try {
con = getConnection();
// ps = con.prepareStatement(insertQuery.toString());
ps = con.prepareStatement(insertQuery);
ps.setString(1, member.getMem_uid());
ps.setString(2, member.getMem_fwd());
ps.setString(3, member.getMem_name());
ps.setString(4, member.getMem_email());
ps.setTimestamp(5, member.getMem_regdate());
ps.setString(6, member.getMem_address());
ps.executeUpdate();
re = 1;
ps.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
return re;
}
public int confirmID(String id) throws Exception{
String sql = "select mem_uid from MEMBERT where mem_uid=?";
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
int re=-1;
try {
con = getConnection();
ps = con.prepareStatement(sql);
ps.setString(1,id);
rs = ps.executeQuery();
if (rs.next()) {
re = 1;
}else {
re = -1;
}
rs.close();
ps.close();
con.close();
} catch (Exception e) {
e.getStackTrace();
}
return re;
}
public int userCheck(String id, String pwd) throws Exception{
int re = -1;
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
String db_mem_pwd="";
String sql = "select mem_fwd from MEMBERT where mem_uid=?";
try {
con = getConnection();
ps = con.prepareStatement(sql);
ps.setString(1, id);
rs = ps.executeQuery();
if (rs.next()) {
db_mem_pwd = rs.getString("mem_fwd");
if (db_mem_pwd.equals(pwd)) {
re=1;//둘 다 맞음
} else {
re=0;//아이디는 맞는데 비밀번호는 틀림
}
} else {
re=-1;//아이디가 존재하지 않음
}
rs.close();
ps.close();
con.close();
} catch (Exception e) {
// TODO: handle exception
}
return re;
}
public MemberBean getMember(String id) throws Exception{
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
String sql = "select * from MEMBERT where mem_uid=?";
MemberBean member = null;
try {
con = getConnection();
ps = con.prepareStatement(sql);
ps.setString(1, id);
rs = ps.executeQuery();
if (rs.next()) {
member = new MemberBean();
// if (member.getMem_uid().equals(rs.getString("mem_uid"))) {
member.setMem_uid(rs.getString("mem_uid"));
member.setMem_fwd(rs.getString("mem_fwd")); member.setMem_name(rs.getString("mem_name")); member.setMem_email(rs.getString("mem_email")); member.setMem_regdate(rs.getTimestamp("mem_regdate")); member.setMem_address(rs.getString("mem_address")); // }
// } else {
}
rs.close();
ps.close();
con.close();
} catch (Exception e) {
// TODO: handle exception
}
return member;
}
}
|
cs |
ㅇㄹ
728x90
'학원 > JSP - 학원' 카테고리의 다른 글
사용자 관리 3단계 1번 (0) | 2022.03.23 |
---|---|
사용자 관리 2단계 2번 (0) | 2022.03.21 |
사용자 관리 1단계 3번 (0) | 2022.03.21 |
사용자 관리 1단계 2번 (0) | 2022.03.21 |
사용자 관리 1단계 1번 (0) | 2022.03.18 |