Advertisement
Guest User

Untitled

a guest
Aug 16th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. package com.exam;
  2.  
  3. import java.sql.*;
  4.  
  5. public class DBConnection {
  6.  
  7. public static Connection getCon() throws SQLException {
  8. // TODO Auto-generated method stub
  9.  
  10. Connection con = null;
  11. try{
  12. Class.forName("com.mysql.jdbc.Driver");
  13. String url="jdbc:mysql://localhost:3306/testdb";
  14. con=DriverManager.getConnection("url", "root", "lovecoding");
  15. con.close();
  16. return con;
  17. }
  18. catch(ClassNotFoundException cnfe){
  19. System.out.println("해당 클래스를 찾을 수 없습니다."+cnfe.getMessage());
  20. return null;
  21. }
  22.  
  23. }
  24.  
  25. }
  26.  
  27. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  28. "http://www.w3.org/TR/html4/loose.dtd">
  29. <html>
  30. <head>
  31. <meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
  32. <title>Insert title here</title>
  33. <style type="text/css">
  34. #regbox{width:300px;}
  35. #regbox label{display:block; width:100px; float:left; }
  36. </style>
  37. </head>
  38. <body>
  39. <form method="post" action="insert.jsp">
  40. <fieldset id="regbox">
  41. <legend>회원가입</legend>
  42. <label for="id">아이디</label>
  43. <input type="text" name="id"/><br/>
  44. <label for="pwd">비밀번호</label>
  45. <input type="password" name="pwd"/><br/>
  46. <input type="submit" value="가입">
  47. <input type="reset" value="취소"/>
  48. </fieldset>
  49. </form>
  50. </body>
  51. </html>
  52.  
  53. <%@page import="java.sql.SQLException" %>
  54. <%@page import="java.sql.PreparedStatement" %>
  55. <%@page language="java" contentType="text/html; charset=euc-kr"
  56. pageEncoding="euc-kr" %>
  57. <%@page import="java.sql.Connection" %>
  58. <%@page import="com.exam.DBConnection" %>
  59. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  60. "http://www.w3.org/TR/html4/loose.dtd">
  61. <html>
  62. <head>
  63. <meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
  64. <title>Insert title here</title>
  65. </head>
  66. <body>
  67. <%
  68. request.setCharacterEncoding("euc-kr");
  69. String id=request.getParameter("id");
  70. String pwd=request.getParameter("pwd");
  71.  
  72. Connection con=null;
  73. PreparedStatement pstmt=null;
  74. String sql="insert into members vlaues(?,?,sysdate)";
  75. int n=0;
  76.  
  77. try{
  78. con=DBConnection.getCon();
  79. pstmt=con.prepareStatement(sql);
  80. pstmt.setString(1, id);
  81. pstmt.setString(2, pwd);
  82.  
  83. n=pstmt.executeUpdate();
  84. }
  85. catch(SQLException se){
  86. System.out.println(se.getMessage());
  87. }
  88. finally{
  89. try{
  90. if(pstmt!=null) pstmt.close();
  91. if(con!=null) con.close();
  92. }
  93. catch(SQLException se){
  94. System.out.println(se.getMessage());
  95. }
  96. }
  97. %>
  98. <script type="text/javascript">
  99. if(<%=n%>>0){
  100. alert("정상적으로 회원가입되었습니다.");
  101. location.href="../index.html";
  102. }
  103. else{
  104. alert("회원가입에 실패했습니다.");
  105. history.go(-1);
  106. }
  107. </script>
  108. </body>
  109. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement