Revert "Revert "1. DB 연결 관련 Dao, Vo 자바 파일 생성""

This reverts commit 9bc7963d4c.
This commit is contained in:
mcutegs2
2020-06-15 19:25:27 +09:00
parent 9bc7963d4c
commit a7dd2177cd
10 changed files with 440 additions and 25 deletions

View File

@@ -0,0 +1,28 @@
package DB;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class BasicDao {
private String driver = "com.mysql.jdbc.Driver";
private String url = "jdbc:mysql://@110.35.119.108:3307:hospital_DB";
private String user = "mes";
private String password = "Mestkdrhdghldmlth1!";
protected Connection conn;
protected PreparedStatement psmt;
protected ResultSet rs;
public BasicDao() {
try {
Class.forName(this.driver);
this.conn = DriverManager.getConnection(this.url, this.user, this.password);
} catch (SQLException | ClassNotFoundException var2) {
var2.printStackTrace();
}
}
}

View File

@@ -0,0 +1,115 @@
package DB;
import java.sql.SQLException;
import java.util.ArrayList;
public class BoardDao extends BasicDao {
private final String SELECT_ALL = "SELECT * FROM user_tbl";
public BoardDao() {
}
public ArrayList<BoardVo> select() {
ArrayList list = new ArrayList();
try {
this.psmt = this.conn.prepareStatement("SELECT * FROM user_tbl");
this.rs = this.psmt.executeQuery();
while(this.rs.next()) {
BoardVo vo = new BoardVo();
vo.u_ID(this.rs.getInt("u_ID"));
vo.setWriter(this.rs.getString("writer"));
vo.setwDate(this.rs.getDate("wDate"));
vo.setTitle(this.rs.getString("title"));
vo.setContent(this.rs.getString("content"));
vo.setHit(this.rs.getInt("hit"));
list.add(vo);
}
} catch (SQLException var3) {
var3.printStackTrace();
}
return list;
}
public BoardVo select(BoardVo vo) {
try {
int boardId = vo.getBoardId();
this.psmt = this.conn.prepareStatement("SELECT * FROM BOARD WHERE boardId = ?");
this.psmt.setInt(1, boardId);
this.rs = this.psmt.executeQuery();
if (this.rs.next()) {
vo.setWriter(this.rs.getString("writer"));
vo.setwDate(this.rs.getDate("wDate"));
vo.setTitle(this.rs.getString("title"));
vo.setContent(this.rs.getString("content"));
vo.setHit(this.rs.getInt("hit"));
this.hitCountUp(this.rs.getInt("boardId"));
}
} catch (SQLException var3) {
var3.printStackTrace();
}
return vo;
}
public int insert(BoardVo vo) {
int n = 0;
try {
this.psmt = this.conn.prepareStatement("insert into board values(b_num.nextval,?,?,?,?,0)");
this.psmt.setString(1, vo.getWriter());
this.psmt.setDate(2, vo.getwDate());
this.psmt.setString(3, vo.getTitle());
this.psmt.setString(4, vo.getContent());
n = this.psmt.executeUpdate();
} catch (SQLException var4) {
var4.printStackTrace();
}
return n;
}
public int update(BoardVo vo) {
int n = 0;
try {
this.psmt = this.conn.prepareStatement("update board set content = ? where boardId = ?");
this.psmt.setInt(1, vo.getBoardId());
this.psmt.setString(2, vo.getContent());
n = this.psmt.executeUpdate();
} catch (SQLException var4) {
var4.printStackTrace();
}
return n;
}
public int delete(BoardVo vo) {
int n = 0;
try {
this.psmt = this.conn.prepareStatement("delete from board where boardId = ?");
this.psmt.setInt(1, vo.getBoardId());
n = this.psmt.executeUpdate();
} catch (SQLException var4) {
var4.printStackTrace();
}
return n;
}
public void hitCountUp(int id) {
String var2 = "UPDATE board set hit = hit+1 where boardId = ?";
try {
this.psmt = this.conn.prepareStatement("UPDATE board set hit = hit+1 where boardId = ?");
this.psmt.setInt(1, id);
this.psmt.executeUpdate();
} catch (SQLException var4) {
var4.printStackTrace();
}
}
}

View File

@@ -0,0 +1,69 @@
package DB;
import java.sql.Date;
public class BoardVo {
int boardId;
String writer;
String u_ID;
Date wDate;
String title;
String content;
int hit;
public BoardVo() {
}
public String getWriter() {
return this.writer;
}
public void setWriter(String writer) {
this.writer = writer;
}
public int getBoardId() {
return this.boardId;
}
public void setBoardId(int boardId) {
this.boardId = boardId;
}
public Date getwDate() {
return this.wDate;
}
public void setwDate(Date wDate) {
this.wDate = wDate;
}
public String getTitle() {
return this.title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return this.content;
}
public void setContent(String content) {
this.content = content;
}
public int getHit() {
return this.hit;
}
public void setHit(int hit) {
this.hit = hit;
}
public void u_ID(String u_ID) {
// TODO Auto-generated method stub
}
}

View File

@@ -0,0 +1,78 @@
package DB;
import java.sql.SQLException;
import java.util.ArrayList;
public class MemberDao extends BasicDao {
private final String MEMBER_LIST = "SELECT * FROM member";
private final String MEMBER_CHECK = "SELECT * FROM member WHERE id = ? and pw = ?";
private final String MEMBER_INSERT = "INSERT into member values(?,?,?,?,?,?,?)";
public MemberDao() {
}
public ArrayList<MemberVo> select() {
ArrayList list = new ArrayList();
try {
this.psmt = this.conn.prepareStatement("SELECT * FROM member");
this.rs = this.psmt.executeQuery();
while(this.rs.next()) {
MemberVo member = new MemberVo();
member.setId(this.rs.getString("ID"));
member.setName(this.rs.getString("NAME"));
member.setAddr(this.rs.getString("ADDR"));
member.setTel(this.rs.getString("TEL"));
member.setGender(this.rs.getString("GENDER"));
member.setHobby(this.rs.getString("HOBBY"));
list.add(member);
}
} catch (SQLException var3) {
var3.printStackTrace();
}
return list;
}
public MemberVo selectMember(MemberVo member) {
MemberVo vo = null;
try {
this.psmt = this.conn.prepareStatement("SELECT * FROM member WHERE id = ? and pw = ?");
this.psmt.setString(1, member.getId());
this.psmt.setString(2, member.getPw());
this.rs = this.psmt.executeQuery();
if (this.rs.next()) {
String id = this.rs.getString("id");
String pw = this.rs.getString("pw");
vo = new MemberVo(id, pw);
}
} catch (SQLException var5) {
var5.printStackTrace();
}
return vo;
}
public int memberInsert(MemberVo member) {
int n = 0;
try {
this.psmt = this.conn.prepareStatement("INSERT into member values(?,?,?,?,?,?,?)");
this.psmt.setString(1, member.getId());
this.psmt.setString(2, member.getName());
this.psmt.setString(3, member.getPw());
this.psmt.setString(4, member.getAddr());
this.psmt.setString(5, member.getTel());
this.psmt.setString(6, member.getGender());
this.psmt.setString(7, member.getHobby());
n = this.psmt.executeUpdate();
} catch (SQLException var4) {
var4.printStackTrace();
}
return n;
}
}

View File

@@ -0,0 +1,75 @@
package DB;
public class MemberVo {
public String id;
public String name;
public String pw;
public String addr;
public String tel;
public String gender;
public String hobby;
public MemberVo() {
}
public MemberVo(String id, String pw) {
this.id = id;
this.pw = pw;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getAddr() {
return this.addr;
}
public void setAddr(String addr) {
this.addr = addr;
}
public String getTel() {
return this.tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getGender() {
return this.gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getHobby() {
return this.hobby;
}
public void setHobby(String hobby) {
this.hobby = hobby;
}
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
public String getPw() {
return this.pw;
}
public void setPw(String pw) {
this.pw = pw;
}
}

View File

@@ -0,0 +1,20 @@
package command;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import DB.BoardDao;
import DB.BoardVo;
public class BoardViewCommand implements Command {
public BoardViewCommand() {
}
public String exec(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
return "boardView.jsp";
}
}

View File

@@ -11,6 +11,7 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import command.BoardViewCommand;
import command.Command;
import command.HomeCommand;
import command.UserJoinCommand;
@@ -36,6 +37,7 @@ public class Fcontroller extends HttpServlet {
list.put("/patientlogin.do", new patientLoginCommand()); // 환자 로그인 처리
list.put ("/UserJoin.do", new UserJoinCommand()); // 임직원 회원가입 페이지
list.put ("/patientJoin.do", new patientJoinCommand()); // 환자 회원가입 페이지
list.put("/boardView.do", new BoardViewCommand()); // 데이터 보기 test 페이지
//이 부분에 계속적으로 매핑을 추가하면 됨
}

View File

@@ -0,0 +1,50 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<style>
#menu1 ul li a{
text-decoration: none;
color: white;
}
#totalDiv{
width : 800px;
display: block;
margin : 0 auto;
}
h1 {
text-align : center;
}
</style>
</head>
<body>
<div class="container" style="height : 80%">
<div class="row">
<div class="col h-100">
<table class="table table-dark">
<tr>
<th>작성자</th>
<td>${board.writer}</td>
<th>작성일자</th>
<td>${board.wDate}</td>
</tr>
<tr>
<th>제목</th>
<td colspan="3">${board.title}</td>
</tr>
<tr>
<th class="h-100 d-inline-block">내용</th>
<td colspan="3">${board.content}</td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>

View File

@@ -5,7 +5,7 @@
<head>
<meta charset="UTF-8">
<title>병원 관리 시스템</title>
<jsp:forward page="/home.do"></jsp:forward>
<jsp:forward page="/boardView.do"></jsp:forward>
</head>
</FORM>
</BODY>

View File

@@ -56,7 +56,7 @@
<table class="table">
<tbody>
<tr>
<th scope="row">회원명</th><td colspan="3"><input class="form-control" style="width:30%" type="text" id="name" name="name" maxlength="10"></td>
<th scope="row">환자성명</th><td colspan="3"><input class="form-control" style="width:30%" type="text" id="name" name="name" maxlength="10"></td>
</tr>
<tr>
<th scope="row">회원ID</th><td colspan="3"> <input class="form-control d-inline" style="width:30%" type="text" id="id" name="id" maxlength="10">&nbsp;&nbsp;<input class="btn btn-info" type="button" value="중복확인" onclick="idValidCheck()"></td>
@@ -80,7 +80,7 @@
<th scope="row">생년월일</th><td><input class="form-control" id="u_birth" name="u_birth" type="number" style="width:30%" maxlength="6"></td>
</tr>
<tr>
<th scope="row">병과</th><td><input class="form-control" id="u_car_num" name="u_car_num" type="text" style="width:30%" maxlength="15"></td>
<th scope="row">나이</th><td><input class="form-control" id="p_age" name="p_age" type="number" style="width:30%" maxlength="3"></td>
</tr>
<tr>
<th scope="row">성별</th>
@@ -95,28 +95,6 @@
</div>
</td>
</tr>
<tr>
<th scope="row">직책</th>
<td colspan="3">
<div class="custom-control custom-checkbox custom-control-inline">
<input type="checkbox" class="custom-control-input" id="u_post_0" name="u_post" value="사원">&nbsp;&nbsp;&nbsp;
<label class="custom-control-label" for="u_post_0">사원</label>
</div>
<div class="custom-control custom-checkbox custom-control-inline">
<input type="checkbox" class="custom-control-input" id="u_post_1" name="u_post" value="주임">&nbsp;&nbsp;&nbsp;
<label class="custom-control-label" for="u_post_1">주임</label>
</div>
<div class="custom-control custom-checkbox custom-control-inline">
<input type="checkbox" class="custom-control-input" id="u_post_2" name="u_post" value="대리">&nbsp;&nbsp;&nbsp;
<label class="custom-control-label" for="u_post_2">대리</label>
</div>
<div class="custom-control custom-checkbox custom-control-inline">
<input type="checkbox" class="custom-control-input" id="u_post_3" name="u_post" value="과장">&nbsp;&nbsp;&nbsp;
<label class="custom-control-label" for="u_post_3">과장</label>
</div>
</td>
</tr>
</tbody>
</table>
</div>