학원/JSP - 학원

사용자 관리 1단계 3번

수풀속의고라니 2022. 3. 21. 14:33
728x90

registerOk.jsp

 

 

 

- 중복 아이디가 발생하면 뒤로 돌아가도록 history.back();을 준다.

- 한글처리 해주기 위해서 request.setChar~~을 스크립트릿 안에 넣어준다.

MemberDBBean.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
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;
    }
}
cs

 

- 내가 우너래 했던거 오류났었음

- 일단 insertMember메소드 부분에 values가 아니라 value라고 되어있는게 문제(이게 문제였음)

- 그리고 server.xml의 magic 부분에 소스 넣어줘야 함

 

728x90