Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.exam;
- import java.sql.*;
- public class DBConnection {
- public static Connection getCon() throws SQLException {
- // TODO Auto-generated method stub
- Connection con = null;
- try{
- Class.forName("com.mysql.jdbc.Driver");
- String url="jdbc:mysql://localhost:3306/testdb";
- con=DriverManager.getConnection("url", "root", "lovecoding");
- con.close();
- return con;
- }
- catch(ClassNotFoundException cnfe){
- System.out.println("해당 클래스를 찾을 수 없습니다."+cnfe.getMessage());
- return null;
- }
- }
- }
- <!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">
- <title>Insert title here</title>
- <style type="text/css">
- #regbox{width:300px;}
- #regbox label{display:block; width:100px; float:left; }
- </style>
- </head>
- <body>
- <form method="post" action="insert.jsp">
- <fieldset id="regbox">
- <legend>회원가입</legend>
- <label for="id">아이디</label>
- <input type="text" name="id"/><br/>
- <label for="pwd">비밀번호</label>
- <input type="password" name="pwd"/><br/>
- <input type="submit" value="가입">
- <input type="reset" value="취소"/>
- </fieldset>
- </form>
- </body>
- </html>
- <%@page import="java.sql.SQLException" %>
- <%@page import="java.sql.PreparedStatement" %>
- <%@page language="java" contentType="text/html; charset=euc-kr"
- pageEncoding="euc-kr" %>
- <%@page import="java.sql.Connection" %>
- <%@page import="com.exam.DBConnection" %>
- <!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">
- <title>Insert title here</title>
- </head>
- <body>
- <%
- request.setCharacterEncoding("euc-kr");
- String id=request.getParameter("id");
- String pwd=request.getParameter("pwd");
- Connection con=null;
- PreparedStatement pstmt=null;
- String sql="insert into members vlaues(?,?,sysdate)";
- int n=0;
- try{
- con=DBConnection.getCon();
- pstmt=con.prepareStatement(sql);
- pstmt.setString(1, id);
- pstmt.setString(2, pwd);
- n=pstmt.executeUpdate();
- }
- catch(SQLException se){
- System.out.println(se.getMessage());
- }
- finally{
- try{
- if(pstmt!=null) pstmt.close();
- if(con!=null) con.close();
- }
- catch(SQLException se){
- System.out.println(se.getMessage());
- }
- }
- %>
- <script type="text/javascript">
- if(<%=n%>>0){
- alert("정상적으로 회원가입되었습니다.");
- location.href="../index.html";
- }
- else{
- alert("회원가입에 실패했습니다.");
- history.go(-1);
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement