깜냥
142
2017-06-19 19:06:53.0
1
134

JSP 데이터베이스에 정보를 입력되지 않습니다.


회원가입 웹을 만들면서 MYSQL 에 테이블도 만들고 연결 테스트까지 했습니다. 

데이터베이스에 연결은 되는데 데이터를 입력하고 회원가입을 누르면 회원가입 실패라고 나오는데

어디서 잘 못 된건지 잘 모르겠습니다.

<MemberDao.java>

package my.member;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import my.util.ConnUtil;

public class MemberDao {
	public int insertMember(MemberVo vo){
		  int rst = 0;
		  Connection conn = null;
		  PreparedStatement ps = null;
		  try{
		   conn = ConnUtil.getConnection();
		   String sql = "insert into members values(?,?,?,?,?,?,?,?,sysdate())";
		   ps = conn.prepareStatement(sql);
		   
		   ps.setString(1, vo.getDevice_id() );
		   ps.setString(2, vo.getUsr_id());
		   ps.setString(3, vo.getUsr_password());
		   ps.setString(4, vo.getPhone_num());
		   ps.setString(5, vo.getE_mail());
		   ps.setString(6, vo.getAp_ssid());
		   ps.setString(7, vo.getAp_password());
		   ps.setString(8, vo.getName());
		   rst = ps.executeUpdate();
		  }catch(Exception e){
		   e.printStackTrace();
		  }finally{
		   ConnUtil.close(ps, conn);
		  }
		  return rst;
		 }

<회원가입 폼>

<%@ page language="java" contentType="text/html; charset=EUC-KR"
 pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<script type="text/javascript">

   /* function passchk(){
	 var usr_password = document.form.usr_password.value;
	 var pass3 = document.form.pass3.value;
	 if (pass3.length == 0 || pass3 == null) {
	  document.form.chk.value = "비밀번호를 입력하세요";
	  right = 0;
	 } else if (usr_password != pass3) {
	  document.form.chk.value = "비밀번호가 다릅니다.";
	  right = 0;
	 } else {   
	  document.form.chk.value = "비밀번호가 동일합니다.";
	  right = 1;
	 }
	 return;
	}   */
	
function idcheck(){
	 var usr_id = document.form.usr_id.value;
	 if(usr_id.length<1 || usr_id==null){
	  alert("중복체크할 아이디를 입력하십시오");
	  return false;
	 }
	 var url = "idCheck.jsp?usr_id=" + usr_id;
	 window.open(url, "get", "height = 180, width = 300");
	}
	
var right = 0;
function regChk(){
	 var usr_id = document.form.usr_id.value;
	 var regx = /^[a-zA-Z0-9]*$/;
	 if(usr_id.length==0 || usr_id==null){
	  alert("아이디를 입력하십시오");
	  return false;
	 }
	 var usr_password = document.form.usr_password.value;
	 if(usr_password.length==0 || usr_password==null){
	  alert("비밀번호를 입력하십시오");
	  return false;
	 }
	 if (chk1.test(usr_password) && chk2.test(usr_password)){
	 }else{
	  alert("비밀번호는 영어, 숫자 조합입니다.");
	  return false;
	 }
	 if(right == 0){
		 alert("비밀번호가 동일한지 확인하시오");
		 return false;
	 } 
	 document.form.submit();
}

</script>

<title>회원가입 창</title>
</head>

<body>
<form action="memberProc.jsp" name="form" method="post">

 <table width="1400" height="650">
  <tr>
   <td height="15%"><span style="padding-left: 160px"></span>
   </td>
  </tr>
  <tr>
   <td height="60%" align="center" valign="top">
   <hr><br>
   <p align="left" style="padding-left:160px">
   <b>개인정보입력</b>
   <br><br>
   
  Device ID : <input type="text" size="10" maxlength="15" name="device_id"><br><br>
  User ID : <input type="text" size="10" maxlength="15" name="usr_id">
      &nbsp;<input type="button" value="중복체크" onclick="idcheck()" align="middle"><br><br>
   비밀번호 : <input type="password" size="15" maxlength="20" name="usr_password"><br><br>
   <!-- 비밀번호 확인 : <input type="password" size="15" maxlength="20" name="pass3" onblur="passchk()">&nbsp;
             <input type="text" style="border-width: 0px" size="20" name="chk" value="비밀번호를 입력하세요" readonly="readonly"><br><br> -->
   휴대폰 : <input type="text" name="phone_num"><br><br>
   이메일 : <input type="text" size="15" name="e_mail"><br><br>
  SSID : <input type="text" size="10" maxlength="15" name="ap_ssid"><br><br>
   비밀번호 : <input type="password" size="15" maxlength="20" name="ap_password"><br><br>  
   이름 : <input type="text" name="name"><br><br>
  </td>
  </tr>
  <tr>
   <td align="center">
   <hr><br>
    <input type="submit" value="가입신청" onclick="regChk()">&nbsp;
    <input type="reset" value="다시입력">&nbsp;
    <input type="button" value="취소"  onclick="regCancel()">
   </td>
  </tr>
 </table>
</form>
</body>
</html>

<연결>

package my.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class ConnUtil {
 static {
  try {
   String driverName = "com.mysql.jdbc.Driver";
   Class.forName(driverName);
  } catch (ClassNotFoundException e) {
   e.printStackTrace();
  }
 }
 public static Connection getConnection() throws SQLException{
  String url = "jdbc:mysql://localhost:3306/gggg";
  String id = "root";
  String password = "gs";
  Connection conn = DriverManager.getConnection(url, id, password);
  return conn;
 }
 public static void close(PreparedStatement ps, Connection conn){
  if(ps != null){try{ps.close();}catch(SQLException e){e.printStackTrace();}}
  if(conn != null){try{conn.close();}catch(SQLException e){e.printStackTrace();}}
 }
 public static void close(ResultSet rs, PreparedStatement ps, Connection conn){
  if(rs != null){try{rs.close();}catch(SQLException e){e.printStackTrace();}}
  close(ps, conn);
 }
}

<성공 여부>

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
 <jsp:useBean id="dao" class="my.member.MemberDao"/>
 <jsp:useBean id="vo" class="my.member.MemberVo"/>
 <jsp:setProperty property="*" name="vo"/>
<%
 int rst = 0;
 request.setCharacterEncoding("euc-kr");
 rst = dao.insertMember(vo);
 if(rst>0){
%>
<script type="text/javascript">
alert("회원가입 성공");
</script>
<%}else{ %>
<script type="text/javascript">
alert("회원가입 실패");
history.go(-1);
</script>
<%} %>



*만약 테이블의 처음 부분인 device_id 부분은 제가 직접 등록하고 나머지 부분만 웹에서 입력해서 저장하려고 한다면 어떻게 해야되나요?

0
0
  • 답변 1

  • 아로시
    333
    2017-06-20 15:34:07.0
    dao단에서 혹시 에러가 발생했나요?
    0
  • 로그인을 하시면 답변을 등록할 수 있습니다.