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
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<%@ page import = "kr.or.ksmart.dao.Mdao" %>
<%@ page import = "kr.or.ksmart.dto.Member" %>
<%
    String id = request.getParameter("id"); // 로그인 폼에서 넘어온 아이디 저장
    String pw = request.getParameter("pw"); // 로그인 폼에서 넘어온 비번 저장
    System.out.println(id + "<-- id");
    System.out.println(pw + "<-- pw");
 
    Mdao dao = new Mdao(); // Mdao클래스의 객체 생성 및 할당
    int ok = dao.mLoginCheck(id,pw); // dao 객체내의  mLoginCheck 메소드 호출후 리턴 값 저장
    System.out.println(ok + "<===리턴 받은 ok");
    
    Member member = new Member(); // Member 클래스 객체 생성
    
    if(ok == (1)) {    // 변수 ok에 저장된 값에 따라 분기문 작성
        member = dao.mGetForSession(id);    //dao 객체내의 mGetForSession메소드 호출후 리턴되는 member 객체주소값 저장
        session.setAttribute("S_NAME", member.getM_name()); // setAttribute메소드를 호출하여 member 객체 내의 get메소드로 호출되는 값을 변수에 저장
        session.setAttribute("S_LEVEL", member.getM_level());
        session.setAttribute("S_ID", member.getM_id());
        //response.sendRedirect(request.getContextPath()+"/index.jsp");
%>
        <script type="text/javascript">
            alert('로그인성공');
            location.href='<%= request.getContextPath()%>/index.jsp';
        </script>
<%
    } else if(ok == 2) {
        System.out.println("04 비번 불일치");
%>
        <script type="text/javascript">
            alert('비번불일치');
            location.href='<%= request.getContextPath()%>/index.jsp';
        </script>
<%
    } else if(ok == 3) {
        System.out.println("02 아이디 불일치");
%>    
        <script type="text/javascript">
            alert('아이디 불일치');
            location.href='<%= request.getContextPath()%>/index.jsp';
        </script>     
<%
    }
%>
 
cs


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
public class Mdao {
    //01입력처리 메서드 선언
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    ArrayList<Member> alm = null;
    // 로그인 성공시에 DB에서 id과 일치하는 행의 id,level,name 컬럼 값을 조회하는 메소드
    public Member mGetForSession(String in_id) throws ClassNotFoundException, SQLException {
        System.out.println("mGetForSession 호출 완료");
        
        DriverDB db = new DriverDB(); // 생성자 메소드로 DB 객체 생성
        System.out.println(db + " : db 객체의 참조 주소값");
        
        conn = db.driverDbcon(); // driverDbcon메소드를 호출하여 Connection 객체 생성(DB연결)
        
        // prepareStatement 메소드로 PreparedStatement객체 생성(쿼리문 실행 준비)
        pstmt = conn.prepareStatement("select m_id, m_level, m_name from tb_member where m_id=?"); 
        pstmt.setString(1, in_id);
        System.out.println(pstmt + "<==pstmt 쿼리문 조회");
        rs = pstmt.executeQuery(); // 쿼리문 실행 후 조회된 테이블 ResultSet 객체에 저장
        
        Member member = new Member(); // 읽어낸 값 Member 객체에 세팅할 준비.
        
        if(rs.next()) { // rs 객체내의 테이블의 행을 조사한다.
            member.setM_id(rs.getString("m_id")); // set 메소드를 호출하여 값을 세팅
            member.setM_level(rs.getString("m_level"));
            member.setM_name(rs.getString("m_name"));
        }
        
        if (rs != null) { //rs 객체 종료
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (pstmt != null) { //pstmt 객체 종료
            try {
                pstmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (conn != null) { // conn 객체 종료
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        
        return member; //member 객체 주소값 리턴
    }
    // 로그인 성공, 비번확인,아이디 확인하는 메소드
    public int mLoginCheck(String in_id,String in_pw) throws ClassNotFoundException, SQLException {
        System.out.println("mLoginCheck 호출 완료");
        
        DriverDB db = new DriverDB();    // 생성자 메소드로 DB 객체 생성
        System.out.println(db + " : db 객체의 참조 주소값");
        
        conn = db.driverDbcon();    // driverDbcon메소드를 호출하여 Connection 객체 생성(DB연결)
        
        // prepareStatement 메소드로 PreparedStatement객체 생성(쿼리문 실행 준비)
        pstmt = conn.prepareStatement("select m_pw from tb_member where m_id=?");
        pstmt.setString(1, in_id);
        System.out.println(pstmt + "<==pstmt 쿼리문 조회");
        rs = pstmt.executeQuery();// 쿼리문 실행 후 조회된 테이블 ResultSet 객체에 저장
        
        int ok = 0//리턴할 값 저장할 변수 초기화.
        
        if(rs.next()) { // rs 테이블내의 행 조회
            if(rs.getString("m_pw").equals(in_pw)) { // 조회된 m_pw 컬럼의 값이 in_pw 변수내의 값과 일치 할 경우 로그인 성공 1 리턴
                System.out.println("로그인 성공");
                 ok = 1;
            } else {
                System.out.println("비번 불일치"); // 다를 경우 실패 2 리턴
                ok = 2;
            }
        } else {
            System.out.println("아이디 불일치"); // 아이디가 다를경우 실패 3리턴
            ok = 3;
        }
        
        if (rs != null) {//rs 객체 종료
            try {
                rs.close();
            } catch (SQLException e) { //pstmt 객체 종료
                e.printStackTrace();
            }
        }
        if (pstmt != null) { // conn 객체 종료
            try {
                pstmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        
        return ok; // ok에 담긴 값 리턴
    }
cs



1. 로그인 폼에서 id,pw 입력 후 전송


2. login_pro에서 전송된 값 저장.


3. 저장된 값을 매개변수로 mLoginCheck 메소드 호출


4. 호출된 메소드 내에서 DB내의 id,pw 값과 비교 후 일치하는 행과 값이 있으면 1, pw가 다르면 2, 행이 없으면 3을 리턴 한다.


5. 리턴 된 값을 변수에 저장한다.


6. 1의 경우는 로그인에 성공했으므로, mGetForSession 메소드를 호출하여 DB내 1명의 회원 정보를 조회하고 member 객체 내에 값을 set 메소드를 호출해서 세팅하고 객체의 주소 값을 리턴 한다.


7. 리턴 된 member 객체의 주소 값을 참조하여, get메소드를 호출하여 세팅된 값을 불러온다.


8. 불러온 값을 setAttribute 메소드의 매개변수로 입력해서 변수에 저장한다. 그리고 로그인 성공 경고창을 띄우고 index페이지로 리다이렉트 한다.


9. 2,3의 경우는 로그인 실패의 경우이므로 비번 불일치, 아이디 불일치 경고창을 띄우고 index페이지로 리다이렉트 한다.





이상 JSP DTO,DAO를 활용한 로그인 세션 처리에 대해 정리하여 보았다.




오늘 Github에서 Repository를 만들고 프로젝트를 등록하는 방법에 대해서 익혀보았다.



회원가입하고, 로그인 하는 부분은 생략하였다.



로그인 후 먼저 이 화면에서 New repository를 선택한다.


처음 가입하였을 경우에는 선택 할 필요없이 먼저 Repository를 만드는 화면이 나왔을 것이다.



새로운 Repository를 만드는 화면이다.


Repository name란에 원하는 이름을 입력하고 Repository의 부가 설명을 원하면 Description란에 설명을 적어준다.


공개를 원하면 public 아니면 private을 선택한다.


다른 선택사항은 잘 모르겠으므로 Create repository를 클릭하여 넘어간다.




이제 Repository가 만들어졌다.


중간에 HTTPS / SSH 라고 보이는 곳 우측의 주소가 이 Repository의 주소가 된다.


이제 이클립스로 가자.




이클립스에서 진행중인 프로젝트에 우클릭을 하면 나오는 메뉴들중 Team으로 커서를 올린다.


그리고 열리는 패널에서 Share Project...를 클릭한다.





그러면 이러한 창이 뜨는데, Create를 클릭하여 Repository가 저장될 폴더를 지정하고 Project를 체크 한 후 Finish를 클릭하면 된다.



이제 우리는 git과 공유할 PC내의 서버를 지정한 것이다.





또한, Git Staging이라는 탭이 하나 더 생긴것을 볼 수 있다.


여기서는 Commit을 진행할 파일 (Staged Changes)과 진행하지 않을 파일 (Unstaged Changes)를 정하고,


Commit할때 남길 메세지를 작성 할 수 있다. 또한 Commit과 Push를 한번에 진행 할 것인지, Commit만 진행 할 것인지도 결정 할 수 있다.


이번에는 Commit and Push만 실행해 보겠다.


Push Branch master라는 창이 열린다.

여기서는 아까 만들었던 Repository의 주소를 URI에 붙여넣기 하고, 

Authentication에 로그인 할때 사용하는 ID,Password를 입력하고 Next를 클릭한다.



잘 모르는 설정이므로, Next를 눌러 넘어간다.



이제 Push 처리에 대한 설정이 완료 되었다. Finish를 클릭한다.



우측 아래에 Push 진행상황이 막대그래프로 표시된다.


Push가 끝나면 완료 창이 뜨는데, 실수로 꺼버려서 캡쳐하지 못했다.





다시 Github로 돌아가서 페이지를 새로고침하면, 이렇게 변함을 알 수 있다.





최상위 프로젝트 명을 클릭하면, 프로젝트 내의 폴더/파일들이 잘 Push되었음을 확인 할 수 있다.



1 commit 탭을 클릭하면 Commit이 된 시간, 처리한 유저, 메세지등을 확인할 수 있다.




Commit 메시지 부분을 클릭하면 추가/수정/삭제된 코드를 바로 확인 할 수 있게 해준다.




여기까지 오늘은 Github에 팀 프로젝트를 등록하는 방법에 대해 간략하게 정리해 보았다.











연산자


모든 프로그래밍 언어에는 연산자가 포함되어 있다.


자바스크립트의 연산자에는 산술, 문자결합, 대입, 증감, 비교, 논리, 삼항 연산자가 있다.



산술 연산자


연산자 

사용법 

의미 

 +

a+b 

a와 b를 더한다 

 -

a-b

 a에서 b를 뺀다

*

a*b 

 a와 b를 곱한다

 /

 a/b

 a를 b로 나눈다

 %

a%b 

a를 b로 나눈 나머지를 구한다



문자결합 연산자


문자 + 문자 = 문자문자


1
2
3
4
5
6
7
8
9
<head>
    <meta charset="UTF-8">
    <title>변수선언</title>
    <script>
        var x = "안녕";
        let y = "하세요";
        document.write(x+y);
    </script>
</head>
cs




대입 연산자

데이터를 변수에 저장할 때 사용하는 연산자다.

연산자 

의미 

a=b 

a에 b를 대입한다 

a+=b 

a+b를 a에 대입한다 

a*=b 

 a*b를 a에 대입한다

 a/=b

 a/b를 a에 대입한다

 a%=b

a%b를 a에 대입한다 



증감 연산자

숫자형 데이터의 값을 1씩 변화 시키는 연산자이다.

++ --가 있는데 앞에 붙으면 증가나 감소가 먼저 실행되고 나머지 계산이 이루어지고, 뒤에 붙으면 다른 계산 이후에 증감이 이루어진다.


비교 연산자

 연산자

의미 

a>b 

a가 b보다 크다 

a<b 

a가 b보다 작다 

 a>=b

a가 b보다 크거나 같다

 a<=b

a가 b보다 작거나 같다 

 a==b

a와 b는 같다 (숫자,문자형 구분하지 않음)

 a != b

a와 b는 다르다 (숫자,문자형 구분하지 않음)

 a===b

a와b는 같다 (숫자,문자형 구분) 

a!==b 

a와 b는 다르다 (숫자,문자형 구분) 


논리 연산자

|| : or , 결과값 둘 중 하나가 true면 true를 반환한다. 

&& : and , 결과값 둘 모두 true여야 true를 반환한다.

! : not, true는 false로 false는 true를 반환한다.



연산자의 우선순위

() > 단항 연산자 > 산술 연산자 > 비교 연산자 > 논리 연산자 > 대입 연산자

우측에 있는 것일수록 우선순위가 높다.


삼항 연산자

?를 포함하여 피연산자가 3개인것을 뜻하는데, if문으로 대체가 가능하다.

ex) a>b?"no":"yes";

true일 경우 no가 false일경우 yes가 출력된다.





자바스크립트의 변수


변수는 변하는 데이터를 저장하는 공간이다. 한 개의 변수에는 한 개의 값만이 저장될 수 있다.


변수의 종류에는 문자형, 숫자형, 논리형, Null형이 있다.




변수 선언


다음은 변수를 선언하는 방법이다.


1
2
3
4
5
6
7
8
9
10
11
<head>
    <meta charset="UTF-8">
    <title>변수선언</title>
    <script>
        var x;
        let y;
        x = 100;
        y = 30;
        document.write(x+y);
    </script>
</head>
cs


선언하고자 하는 변수명 앞에 var이나 let을 붙여주면 되는데,


var은 한번 선언하면 페이지 전체에서 사용할 수 있는 변수이고, let은 특정 메소드 안에서 사용할 수 있는 변수가 된다.



typeof는 변수 앞에 붙었을 경우에 변수의 데이터 타입을 알려준다.




자바스크립트의 선언


자바스크립트는 선언문을 기준으로 시작한다.


1
2
3
<script>
    자바스크립트 코드
</script>
cs


head나 body태그 안에 선언이 가능하다. 하지만 대부분 head태그 안에 선언한다.


1
2
3
4
5
6
7
<head>
    <meta charset="EUC-KR">
    <title>선언문</title>
    <script>
        document.write("환영합니다");
    </script>
</head>
cs


자바스크립트의 주석은 한 줄 주석의 경우 '//'를 사용하고, 두 줄 이상의 주석은 '/* */'를 사용한다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
<head>
    <meta charset="EUC-KR">
    <title>선언문</title>
    <script>
        //한 줄 주석 입니다.
        /* 
            여러줄
            주석
            입니다
        */
        document.write("환영합니다");
    </script>
</head>
 
cs

자바스크립트는 html페이지 내에서 파일을 따로 분리하여 외부로부터 불러오는 형태가 가능하다.

1
2
3
4
5
6
<head>
    <meta charset="UTF-8">
    <title> 외부 자바스크립트 연동 </title>
    <script src="js/example.js"></script>
</head>
 
cs







JSP 페이지에서 게시판을 만들고, 게시글 내의 페이지에서 덧글 기능을 추가하여 보자.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//board 상세 내용 출력하는 부분
                    
                    String sql = "SELECT board_no,member_id,board_title,board_content,board_pw,board_date FROM board where board_no=?";
                    pstmt = conn.prepareStatement(sql);
                    pstmt.setString(1,sendBoardNo);
                    System.out.println(pstmt + " : confirm pstmt");
                    
                    rs = pstmt.executeQuery();
                    
                    
                    if(rs.next()) {
                %>
                        <div id="view_title_box">
                            <span><%=rs.getString(3%></span>
                            <span id="info"><%=rs.getString(2%> | 조회:208 | <%=rs.getString(6%></span>
                        </div>
                        <p id="view_content">
                            <%=rs.getString(4%>
                        </p>
                <%
                    }
                %>
cs


쿼리문은 글 번호가 일치하는 게시물의 번호, 글쓴이의 id, 글 제목, 글 내용, 글 비밀번호, 작성 시간의 부분을 조회하는 내용이다.


rs 객체에 담겨진 테이블은 rs.getString()에 의해 글의 제목, 작성자 id, 글의 내용이 페이지 내에 출력되게 된다.


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
<!-- 덧글 리스트 -->
                <!-- 페이징 or 덧글의 수가 5개까지 허용되도록 --> 
                <%
                    //덧글 리스트 select
                    String commentListQuery = "SELECT member_id, board_comment_content FROM board_comment WHERE board_no=?";
                    pstmt2 = conn.prepareStatement(commentListQuery);
                    pstmt2.setString(1, sendBoardNo);
                    System.out.println(pstmt2 + " : confirm pstmt2");
                    
                    //덧글의 갯수 select
                    String countListQuery = "SELECT count(*) as countList FROM board_comment where board_no=?";
                    pstmt3 = conn.prepareStatement(countListQuery);
                    pstmt3.setString(1, sendBoardNo);
                    
                    rs2 = pstmt2.executeQuery();
                    System.out.println(rs2 + " : confirm rs2");
                    
                    rs3 = pstmt3.executeQuery();
                    System.out.println(rs3 + " : confirm rs3");
                    
                    //덧글 갯수 변수에 저장
                    int countList = 0;
                    if(rs3.next()){
                        countList = rs3.getInt(1);
                    }
                %>
cs


덧글에 관련된 코드이다.


첫번째 쿼리는 글 번호가 일치하는 글의 작성자 id, 덧글들을 board_comment 테이블에서 조회하는 내용이다.


두번째 쿼리는 글 번호가 일치하는 board_comment 내의 모든 행의 갯수를 조회하는 내용이다.


그 후 rs3 객체에 담겨진 두번째 쿼리 실행의 결과 테이블은 countList 변수에 값이 담기게 된다.



                    //덧글 리스트 출력
                    while(rs2.next()){
                %>
                        <tr>
                            <td><%=rs2.getString(1%></td>
                            <td><%=rs2.getString(2%></td>
                        </tr>
                <%
                    }
                %>


덧글 리스트를 출력하는 코드로 rs2 객체내 테이블의 행을 조사하여 컬럼의 값들을 행의 마지막 까지 페이지에 출력하게 한다.


                <!-- 덧글 입력하는 폼 -->
                <form action="./insertCommentAction.jsp" method="post">
                    <div id="comment_box">
                        <img id="title_comment" src="img/title_comment.gif">
                        <textarea name="boardCommentContent"></textarea>
                        <%
                            //로그인 세션이 있을때만 덧글 작성 가능.
                            if(session.getAttribute("loginInfo"!= null){
                                //덧글 갯수가 5개 미만일때 글쓰기 버튼 표시
                                if(countList < 5) {
                        %>
                                    <input type="image" id="ok_ripple" src="img/ok_ripple.gif"><br>
                        <%
                                } else { //덧글갯수가 5개 이상이면 글쓰기 버튼 없애기
                        %>
                                    <img src="img/comment_limit_5.jpg" id="ok_ripple2">
                        <%
                                }
                            } else {//로그인 세션이 없을때는 로그인 먼저 하라는 그림 출력
                        %>
                                <img src="img/first_login.jpg" id="ok_ripple2">
                        <%                                
                            }
                        %>    
                        <input type="hidden" name="boardNo" value="<%=sendBoardNo %>"><br>
                        <input type="hidden" name="loginInfo" value="<%=session.getAttribute("loginInfo")%>">
                    </div>
                </form>

덧글을 입력하는 폼의 코드 부분이다.


폼에서 insertCommentAction.jsp페이지로 post 방식을 통해 값을 넘겨주도록 하였다.


로그인 세션이 있을때애는 덧글 작성확인 이미지 버튼이 표시되게 하였고,


없을때에는 로그인을 먼저 하라는 사진이 표시되도록 하였다.


그리고 덧글이 5개 이상일 경우에는 더 이상 덧글을 작성할 수 없다는 그림을 표시하게 하였다.


1
2
3
4
5
6
7
8
9
10
11
12
13
            // 덧글 사용 쿼리문 작성
            String insertCommentQuery = "INSERT INTO board_comment (board_no, board_comment_content, member_id) VALUES (?, ?, ?)";
            pstmt = conn.prepareStatement(insertCommentQuery);
            pstmt.setInt(1, boardNo);
            pstmt.setString(2, boardCommentContent);
            pstmt.setString(3, loginInfo);
            
            //쿼리문 실행
            pstmt.executeUpdate();
            
            //덧글 작성 글로 리다이렉트
            response.sendRedirect("./boardDetail.jsp?sendboardno=" + boardNo);
 
cs


boardDetail.jsp 페이지에서 전송된 정보를 받아서 mysql데이터 베이스에 입력하도록 하는 페이지다.


쿼리문은 글 번호, 덧글 내용, 작성자 id 컬럼에 입력값을 담아서 삽입하는 내용이다.


PreparedStatement 객체내 executeUpdate()메소드가 실행되어 삽입이 완료 되고, 


boardDetail.jsp의 글 번호에 해당하는 글로 리다이렉트 되도록 하였다.





덧글 리스트와 덧글 작성 부분이다.




덧글이 5개 이상이면 덧글쓰기 버튼이 이미지로 전환된다.


로그인을 하지 않은 상태에서는 로그인을 먼저 하라는 이미지가 출력된다.







이상 JSP를 활용하여 게시글에 덧글 기능을 만들어 보았다.


아직 초보라 실력이 매우 미숙하기에 너른 이해 바랍니다.

현재부터 X개월 이전의 자료를 검색할 때 사용


select * from tb_goods where g_date >= date_add(now(), interval -6 month)


XX일 이후로 지금 까지의 모든 자료를 검색할 때 사용

select * from tb_goods where g_date between '2018-01-15' and now()




'프로그래밍 > MySQL' 카테고리의 다른 글

SQL 오류 (1064)  (0) 2018.05.24
SQL update - where  (0) 2018.05.24
같은 이름의 데이터베이스를 중복 생성시 오류  (0) 2018.05.24
자료 저장소의 의미와 종류  (0) 2018.04.24
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
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<!Doctype html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
        <style>
            * {
                margin:0;
                padding:0;
            }
            ul {
                list-style-type:none;
            }
            body {
                font-family:"맑은 고딕", "돋움";
                font-size:12px;
                color:44444;
            }
            #login_box {
                width:220px;
                height:120px;
                border:solid 1px #bbbbbb;
                border-radius:15px;
                margin:10px 0 0 10px;
                padding:10px 0 0 15px;
            }
            h2 {
                font-family:"Arial";
                margin-bottom:10px;
            }
            #login_box input {
                width:100px;
                height:18px;
            }
            #id_pass, #login_btn {
                display:inline-block;
                vertical-align:top;
            }
            #id_pass span {
                display:inline-block;
                width:20px;
            }
            #pass {
                margin-top:3px;
            }
            #login_btn button {
                margin-left:5px;
                padding:12px;
                border-radius:5px;
            }
            #btns {
                margin:12px 0 0 0;
                text-decoration:underline;
            }
            #btns li {
                margin-left:10px;
                display:inline;
            }
        </style>
    </head>
    <body>
        <form action="./loginAction2.jsp" method="post">
            <div id="login_box">
                <h2>Member Login</h2>
                <ul id="input_button">
                    <li id="id_pass">
                        <ul>
                            <li>
                                <span>ID</span>
                                <input type="text" name="id">
                            </li>
                            <li id="pass">
                                <span>PW</span>
                                <input type="password" name="pw">
                            </li>
                        </ul>
                    </li>
                    <li id="login_btn">
                        <button>로그인</button>
                    </li>
                </ul>
                <ul id="btns">
                    <li>회원가입</li>
                    <li>아이디/비밀번호 찾기</li>
                </ul>
            </div>
        </form>
    </body>
</html>
cs

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
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<%@ page import = "java.sql.*"%>
<!Doctype html>
<%
    //request.setCharacterEncoding("EUC-KR");
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    
    String loginid = request.getParameter("id");
    String loginpw = request.getParameter("pw");
    System.out.println(loginid + "<---loginid");
    System.out.println(loginpw + "<---loginpw");
    
    Class.forName("com.mysql.jdbc.Driver");
    
    String dbaddress = "jdbc:mysql://localhost:3306/member_list?useUnicode=true&characterEncoding=euckr";
    String dbid = "root";
    String dbpw = "java0000";
    
    conn = DriverManager.getConnection(dbaddress, dbid, dbpw);
    System.out.println(conn + "<---conn");
    
    String sql = "SELECT dbid,dbpw,name,phone,email,address,memo,picture from join_member where dbid=? and dbpw=?";
    pstmt = conn.prepareStatement(sql);
    System.out.println(pstmt + "<---01 pstmt");
    
    pstmt.setString(1, loginid);
    pstmt.setString(2, loginpw);
    System.out.println(pstmt + "<---02 pstmt");
    
    rs = pstmt.executeQuery();
    System.out.println(rs + "<---rs");
    
    if(rs.next()) {
        rs.getString("dbid");
        rs.getString("name");
        rs.getString("phone");
        rs.getString("email");
        rs.getString("address");
        rs.getString("memo");
        rs.getString("picture");
        out.println("로그인 성공");
        System.out.println(rs.getString("dbid"));
        System.out.println(rs.getString("name"));
        System.out.println(rs.getString("phone"));
        System.out.println(rs.getString("email"));
        System.out.println(rs.getString("address"));
        System.out.println(rs.getString("memo"));
        System.out.println(rs.getString("picture"));
    } else {
        System.out.println("로그인 실패");
        response.sendRedirect("./loginForm2.jsp");
    }
 
%>
cs





setString(?의 번호, 입력변수) 메소드로 ?에 입력값을 대입해주지 않으면 


com.mysql.jdbc.JDBC4PreparedStatement@14ed38ee: SELECT dbid,dbpw,name,phone,email,address,memo,picture from join_member where dbid=** NOT SPECIFIED ** and dbpw=** NOT SPECIFIED **<---02 pstmt


id password를 입력해도 쿼리문에 값이 입력되지 않아서


java.sql.SQLException: No value specified for parameter 1


예외가 발생한다.



getRequestURI() : 페이지의 주소만 출력한다.



getRequestURL() : 페이지의 주소, 프로토콜, 포트번호까지 출력한다.



DDL (Data Definition Language) :

Data Definition Language is used to define database structure or schema. DDL is also used to specify additional properties of the data. The storage structure and access methods used by the database system by a set of statements in a special type of DDL called a data storage and definition language. These statements defines the implementation details of the database schema, which are usually hidden from the users. The data values stored in the database must satisfy certain consistency constraints.
For example, suppose the university requires that the account balance of a department must never be negative. The DDL provides facilities to specify such constraints. The database system checks these constraints every time the database is updated. In general, a constraint can be arbitrary predicate pertaining to the database. However, arbitrary predicates may be costly to the test. Thus, database system implements integrity constraints that can be tested with minimal overhead.

  1. Domain Constraints : A domain of possible values must be associated with every attribute (for example, integer types, character types, date/time types). Declaring an attribute to be of a particular domain acts as the constraints on the values that it can take.
  2. Referential Integrity : There are cases where we wish to ensure that a value appears in one relation for a given set of attributes also appear in a certain set of attributes in another relation i.e. Referential Integrity. For example, the department listed for each course must be one that actually exists.
  3. Assertions : An assertion is any condition that the database must always satisfy. Domain constraints and Integrity constraints are special form of assertions.
  4. Authorization : We may want to differentiate among the users as far as the type of access they are permitted on various data values in database. These differentiation are expressed in terms of Authorization. The most common being :
    read authorization – which allows reading but not modification of data ;
    insert authorization – which allow insertion of new data but not modification of existing data
    update authorization – which allows modification, but not deletion.

DML (Data Manipulation Language) :

DML statements are used for managing data with in schema objects.
DML are of two types –

  1. Procedural DMLs : require a user to specify what data are needed and how to get those data.
  2. Declerative DMLs (also referred as Non-procedural DMLs) : require a user to specify what data are needed without specifying how to get those data.

    Declerative DMLs are usually easier to learn and use than are procedural DMLs. However, since a user does not have to specify how to get the data, the database system has to figure out an efficient means of accessing data.


DCL (Data Control Language) :

A Data Control Language is a syntax similar to a computer programming language used to control access to data stored in a database (Authorization). In particular, it is a component of Structured Query Language (SQL).


The operations for which privileges may be granted to or revoked from a user or role apply to both the Data definition language (DDL) and the Data manipulation language (DML), and may include CONNECT, SELECT, INSERT, UPDATE, DELETE, EXECUTE and USAGE.


In the Oracle database, executing a DCL command issues an implicit commit. Hence, you cannot roll back the command.



TCL (Transaction Control Language) :

Transaction Control Language commands are used to manage transactions in database. These are used to manage the changes made by DML-statements. It also allows statements to be grouped together into logical transactions.




'프로그래밍 > ---DBMS---' 카테고리의 다른 글

관계 데이터 연산  (0) 2018.09.29
정규화란?  (0) 2018.09.29

+ Recent posts