jsp 아이디찾기 데이터 베이스 연결 문제

조회수 309회
public String idfind(String userName, String userEmail) {
        String id=null;

        try {
            String SQL = "SELECT userID FROM USER WHERE userName=?,userEmail=?";

            pstmt = conn.prepareStatement(SQL);
            pstmt.setString(1,userName);
            pstmt.setString(2,userEmail);
            rs = pstmt.executeQuery();
            if(rs.next()) {
                id=rs.getString("id");

            }

}catch(Exception e) {
    e.printStackTrace();
}return id;
    }

//
   UserDAO userDAO= new UserDAO();

      String id = userDAO.idfind(user.getUserName(), user.getUserEmail());

    %>


  <form name="idsearch" method="post">
      <%
       if (id != null) {

      %>

      <div class = "container">
        <div class = "found-success">
          <h4>  회원님의 아이디는 </h4>  
          <div class ="found-id"><%=id%></div>
          <h4>  입니다 </h4>
         </div>
         <div class = "found-login">
            <input type="button" id="btnLogin" value="로그인" onClick = 'login.jsp()'/>
        </div>
       </div>
      <%
  } else {

 %>
        <div class = "container">
        <div class = "found-fail">
          <h4>  등록된 정보가 없습니다 </h4>  
         </div>
         <div class = "found-login">
            <input type="button" id="btnback" value="다시 찾기" onClick="history.back()"/>
            <input type="button" id="btnjoin" value="회원가입" onClick="join.jsp()"/>
        </div>
       </div>


//
 <div class="container">
       <div class="col-lg-4"></div>
       <div class="col-lg-4">
         <div class="jumbotron" style= "padding-top:20px;">
           <form method = "post" action = "idfindAction.jsp"> 
             <h3 style= "text-align: center;">아이디 찾기</h3>

            <div class= "form-group">
               <input type = "text" class="form-control" placeholder="이름" name="userName" maxlength="20">
             </div>

             <div class= "form-group">
               <input type = "email" class="form-control" placeholder="이메일" name="userEmail" maxlength="20">
             </div>
             <div class = "btnSearch">
             <input type = "submit" class="btn btn-primary" value="찾기" >



           </div>
           </form>
       </div>
    </div>

이렇게 쳤을때 데이터베이스에 있는 아이디를 찾지못하고 바로 찾지 다시찾기로 넘어가는데 어디서 잘못되었는지 일주일동안 못하고 있네요. 혹시 보시다가 발견하면 알려주시면 감사합니다.

  • 자바는 잘 모르지만.. 아마 SQL의 WHERE절에서 콤마 때문에 오류가 나면서 null이 리턴돼서 그러는걸겁니다. 일반적으로 SQL은 WHERE a=b, c=d 하는식으로는 안되고 where a=b AND c=d 하는식으로 AND를 쓰셔야 합니다. 엽토군 2022.9.12 20:37
  • and 를 썼는데도 똑같은거 같아요.. hyejong1234285@gmail.com 2022.9.13 02:25
  • 흠.. conn은 존재하나요? printStackTrace에 나오는 게 아무것도 없나요? 엽토군 2022.9.13 12:28

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)