오라클에서 연결방법
1. 드라이버 연결방식 : 사용자가 많으면 서버에 과부하
Connection con;
PreparedStatement psmt;
ResultSet rs;
String driver="oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521:xe";
Class.forName(driver);
con=DriverManager.getConnection(url, "ezen", "12345");
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="top.jsp" %>
<%@ include file="dbcon.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<section>
<%!
int num;
%>
<%
String sql="select max(num)+1 from db02171";
psmt = con.prepareStatement(sql);
rs = psmt.executeQuery();
if(rs.next()) {
num = rs.getInt(1);
}
%>
<h3 align="center">도서입력정보</h3>
<form action="bookinput.do" method="post" enctype="multipart/form-data">
<table border="1" align="center">
<%-- <tr>
<th>도서번호</th>
<td><input type="text" name="num" value="<%=num%>" readonly></td>
</tr>
<tr>
<th>발간일자</th>
<td><input type="date" name="day"></td>
</tr> --%>
<tr>
<th>도서명</th>
<td><input type="text" name="bookname"></td>
</tr>
<tr>
<th>저자</th>
<td><input type="text" name="writer"></td>
</tr>
<tr>
<th>가격</th>
<td><input type="text" name="price"></td>
</tr>
<tr>
<th>소개의글</th>
<td><textarea rows="10" cols="30" name="bigo"></textarea>
</tr>
<tr>
<th>표지</th>
<td><input type="file" name="cover"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="전송">
<input type="reset" value="리셋">
</td>
</tr>
</table>
</form>
</section>
<jsp:include page="footer.jsp"/>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="top.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<section>
<h3 align="center">도서출력</h3>
<table border="1" align="center" width="1200px">
<tr>
<th>도서번호</th><th>발간일자</th><th>도서명</th>
<th>저자</th><th>표지</th>
</tr>
<c:forEach items="${list}" var="dto">
<tr>
<td>${dto.num}</td><td>${dto.day}</td>
<td>${dto.bookname}</td><td>${dto.writer}</td>
<td><a href="bookout2.jsp?num=${dto.num}"><img src="image/${dto.cover}" width="60px" height="90px"></a></td>
</tr>
</c:forEach>
</table>
</section>
<jsp:include page="footer.jsp"/>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="top.jsp" %>
<%@ include file="dbcon.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<section>
<%!
String cnum;
String bookname,bigo,cover;
%>
<%
request.setCharacterEncoding("utf-8");
cnum = request.getParameter("num");
String sql = "select bookname,bigo,cover from db02171 where num=?";
psmt = con.prepareStatement(sql);
psmt.setString(1, cnum);
rs = psmt.executeQuery();
if(rs.next()) {
bookname = rs.getString(1);
bigo = rs.getString(2);
cover = rs.getString(3);
}
%>
<table border="1" align="center" width="1200px">
<tr>
<th>책제목</th><th>내용</th><th>북커버</th>
</tr>
<tr>
<td><%=bookname%></td><td><%=bigo%></td>
<td>
<img src ="image/<%=cover%>" width="400px" height="600px">
</td>
</tr>
</table>
</section>
<jsp:include page="footer.jsp"/>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="top.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<section>
<h3 align="center">수정할 책 검색</h3>
<form action="bookmodify2.jsp" method="get">
<table border="1" align="center">
<tr>
<th>검색항목</th>
<td>
<select name="item">
<option value="bookname">책제목</option>
<option value="num">책넘버</option>
</select>
</td>
</tr>
<tr>
<th>입력</th>
<td><input type="text" name="value"> </td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="전송">
<input type="reset" value="취소">
</td>
</tr>
</table>
</form>
</section>
<jsp:include page="footer.jsp"/>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="top.jsp" %>
<%@ include file="dbcon.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<section>
<%!
String item,value;
int num,price;
String day,bookname,writer,bigo,cover;
%>
<%
request.setCharacterEncoding("utf-8");
String item = request.getParameter("item");
String value = request.getParameter("value");
String sql = "select * from db02171 where "+item+" like ?";
psmt = con.prepareStatement(sql);
psmt.setString(1, '%'+value+'%');
rs = psmt.executeQuery();
if(rs.next()) {
num = rs.getInt(1);
day = rs.getString(2);
bookname = rs.getString(3);
writer = rs.getString(4);
price = rs.getInt(5);
bigo = rs.getString(6);
cover = rs.getString(7);
}
%>
<h3 align="center">검색 도서 수정</h3>
<form action="bookmodify.do" method="post" enctype="multipart/form-data">
<table border="1" align="center">
<tr>
<th>도서번호</th>
<td><input type="text" name="num" value="<%=num%>" readonly></td>
</tr>
<tr>
<th>발간일자</th>
<td><input type="date" name="day" value="<%=day%>"></td>
</tr>
<tr>
<th>도서명</th>
<td><input type="text" name="bookname" value="<%=bookname%>" readonly></td>
</tr>
<tr>
<th>저자</th>
<td><input type="text" name="writer" value="<%=writer%>"></td>
</tr>
<tr>
<th>가격</th>
<td><input type="text" name="price" value="<%=price%>"></td>
</tr>
<tr>
<th>소개의글</th>
<td><textarea rows="10" cols="30" name="bigo"><%=bigo%></textarea>
</tr>
<tr>
<th>표지</th>
<td>
<input type="file" name="cover">
<img src="image/<%=cover%>" width="40px" height="60px">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="수정">
<input type="reset" value="리셋">
</td>
</tr>
</table>
</form>
</section>
<jsp:include page="footer.jsp"/>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="top.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<section>
<h3 align="center">삭제할 책 검색</h3>
<form action="bookdelete2.jsp" method="get">
<table border="1" align="center">
<tr>
<th>검색항목</th>
<td>
<select name="item">
<option value="bookname">책제목</option>
<option value="num">책넘버</option>
</select>
</td>
</tr>
<tr>
<th>입력</th>
<td><input type="text" name="value"> </td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="전송">
<input type="reset" value="취소">
</td>
</tr>
</table>
</form>
</section>
<jsp:include page="footer.jsp"/>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="top.jsp" %>
<%@ include file="dbcon.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<section>
<%!
String item,value;
int num,price;
String day,bookname,writer,bigo,cover;
%>
<%
request.setCharacterEncoding("utf-8");
String item = request.getParameter("item");
String value = request.getParameter("value");
String sql = "select * from db02171 where "+item+" like ?";
psmt = con.prepareStatement(sql);
psmt.setString(1, '%'+value+'%');
rs = psmt.executeQuery();
if(rs.next()) {
num = rs.getInt(1);
day = rs.getString(2);
bookname = rs.getString(3);
writer = rs.getString(4);
price = rs.getInt(5);
bigo = rs.getString(6);
cover = rs.getString(7);
}
%>
<h3 align="center">검색 도서 삭제확인</h3>
<form action="bookdelete.do" method="post" enctype="multipart/form-data">
<table border="1" align="center">
<tr>
<th>도서번호</th>
<td><input type="text" name="num" value="<%=num%>" readonly></td>
</tr>
<tr>
<th>발간일자</th>
<td><input type="date" name="day" value="<%=day%>" readonly></td>
</tr>
<tr>
<th>도서명</th>
<td><input type="text" name="bookname" value="<%=bookname%>" readonly></td>
</tr>
<tr>
<th>저자</th>
<td><input type="text" name="writer" value="<%=writer%>" readonly></td>
</tr>
<tr>
<th>가격</th>
<td><input type="text" name="price" value="<%=price%>" readonly></td>
</tr>
<tr>
<th>소개의글</th>
<td><textarea rows="10" cols="30" name="bigo" readonly><%=bigo%></textarea>
</tr>
<tr>
<th>표지</th>
<td>
<input type="file" name="cover">
<img src="image/<%=cover%>" width="40px" height="60px">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="삭제">
<input type="reset" value="리셋">
</td>
</tr>
</table>
</form>
</section>
<jsp:include page="footer.jsp"/>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="top.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<section>
<h3 align="center">검색할 책 검색</h3>
<form action="booksearch.do" method="get">
<table border="1" align="center">
<tr>
<th>검색항목</th>
<td>
<select name="item">
<option value="bookname">책제목</option>
<option value="num">책넘버</option>
</select>
</td>
</tr>
<tr>
<th>입력</th>
<td><input type="text" name="value"> </td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="전송">
<input type="reset" value="취소">
</td>
</tr>
</table>
</form>
</section>
<jsp:include page="footer.jsp"/>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="top.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<section>
<h3 align="center">도서출력</h3>
<table border="1" align="center" width="1200px">
<tr>
<th>도서번호</th><th>발간일자</th><th>도서명</th>
<th>저자</th><th>표지</th>
</tr>
<c:forEach items="${list}" var="dto">
<tr>
<td>${dto.num}</td><td>${dto.day}</td>
<td>${dto.bookname}</td><td>${dto.writer}</td>
<td><a href="bookout2.jsp?num=${dto.num}"><img src="image/${dto.cover}" width="60px" height="90px"></a></td>
</tr>
</c:forEach>
</table>
</section>
<jsp:include page="footer.jsp"/>
</html>
package com.ezen;
public class BookDTO {
int num;
String day,bookname,writer;
int price;
String bigo,cover;
public BookDTO() {
}
public BookDTO(int num, String day, String bookname, String writer, int price, String bigo, String cover) {
super();
this.num = num;
this.day = day;
this.bookname = bookname;
this.writer = writer;
this.price = price;
this.bigo = bigo;
this.cover = cover;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getDay() {
return day;
}
public void setDay(String day) {
this.day = day;
}
public String getBookname() {
return bookname;
}
public void setBookname(String bookname) {
this.bookname = bookname;
}
public String getWriter() {
return writer;
}
public void setWriter(String writer) {
this.writer = writer;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public String getBigo() {
return bigo;
}
public void setBigo(String bigo) {
this.bigo = bigo;
}
public String getCover() {
return cover;
}
public void setCover(String cover) {
this.cover = cover;
}
}
package com.ezen;
import javax.naming.NamingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class BookInput implements service{
@Override
public void aaa(HttpServletRequest request, HttpServletResponse response) {
BookDAO dao;
try {
dao = new BookDAO();
dao.insert(request);
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package com.ezen;
import java.util.ArrayList;
import javax.naming.NamingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class BookOut implements service{
@Override
public void aaa(HttpServletRequest request, HttpServletResponse response) {
BookDAO dao;
try {
dao = new BookDAO();
ArrayList<BookDTO> list = dao.out();
request.setAttribute("list", list);
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package com.ezen;
import javax.naming.NamingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class BookModify implements service{
@Override
public void aaa(HttpServletRequest request, HttpServletResponse response) {
BookDAO dao;
try {
dao = new BookDAO();
dao.modify(request);
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package com.ezen;
import javax.naming.NamingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class BookDelete implements service{
@Override
public void aaa(HttpServletRequest request, HttpServletResponse response) {
BookDAO dao;
try {
dao = new BookDAO();
dao.delete(request);
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package com.ezen;
import java.util.ArrayList;
import javax.naming.NamingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class BookSearch implements service{
@Override
public void aaa(HttpServletRequest request, HttpServletResponse response) {
BookDAO dao;
try {
dao = new BookDAO();
ArrayList<BookDTO> list = dao.search(request);
request.setAttribute("list", list);
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package com.ezen;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import com.oreilly.servlet.MultipartRequest;
public class BookDAO {
Connection con;
PreparedStatement psmt;
ResultSet rs;
String driver="oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521:xe";
ArrayList<BookDTO> list = new ArrayList<BookDTO>();
public BookDAO() {
try {
Class.forName(driver);
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
con=DriverManager.getConnection(url, "ezen", "12345");
} catch (SQLException e) {
e.printStackTrace();
}
}
public void insert(HttpServletRequest request) {
String sd = "C://12월국비//JSP//day24_//src//main//webapp//image";
int filesize = 1024*1024*10;
String encType = "utf-8";
try {
MultipartRequest multi = new MultipartRequest(
request,sd,filesize,encType);
// int num = Integer.parseInt(multi.getParameter("num"));
// String day = multi.getParameter("day");
String bookname = multi.getParameter("bookname");
String writer = multi.getParameter("writer");
int price = Integer.parseInt(multi.getParameter("price"));
String bigo = multi.getParameter("bigo");
String cover = multi.getFilesystemName("cover");
// String sql = "insert into db02171 values (?,?,?,?,?,?,?)";
String sql = "insert into db02171 values (BNUM_SEQ.nextval,sysdate,?,?,?,?,?)";
try {
psmt = con.prepareStatement(sql);
// psmt.setInt(1, num);
// psmt.setString(2, day);
// psmt.setString(3, bookname);
// psmt.setString(4, writer);
// psmt.setInt(5, price);
// psmt.setString(6, bigo);
// psmt.setString(7, cover);
psmt.setString(1, bookname);
psmt.setString(2, writer);
psmt.setInt(3, price);
psmt.setString(4, bigo);
psmt.setString(5, cover);
psmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public ArrayList<BookDTO> out() {
String sql = "select * from db02171";
try {
psmt = con.prepareStatement(sql);
rs = psmt.executeQuery();
while(rs.next()) {
int num = rs.getInt(1);
String day = rs.getString(2).substring(0, 10);
String bookname = rs.getString(3);
String writer = rs.getString(4);
int price = rs.getInt(5);
String bigo = rs.getString(6);
String cover = rs.getString(7);
BookDTO dto = new BookDTO();
dto.setNum(num);
dto.setDay(day);
dto.setBookname(bookname);
dto.setWriter(writer);
dto.setPrice(price);
dto.setBigo(bigo);
dto.setCover(cover);
list.add(dto);
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
public void modify(HttpServletRequest request) {
String sd = "C://12월국비//JSP//day24_//src//main//webapp//image";
int filesize = 1024*1024*10;
String encType = "utf-8";
try {
MultipartRequest multi = new MultipartRequest(
request,sd,filesize,encType);
int num = Integer.parseInt(multi.getParameter("num"));
String day = multi.getParameter("day");
String bookname = multi.getParameter("bookname");
String writer = multi.getParameter("writer");
int price = Integer.parseInt(multi.getParameter("price"));
String bigo = multi.getParameter("bigo");
String cover = multi.getFilesystemName("cover");
String sql = "update db02171 set day=?,writer=?,price=?,bigo=?,"
+ "cover=? where num=? and bookname=?";
try {
psmt = con.prepareStatement(sql);
psmt.setString(1, day);
psmt.setString(2, writer);
psmt.setInt(3, price);
psmt.setString(4, bigo);
psmt.setString(5, cover);
psmt.setInt(6, num);
psmt.setString(7, bookname);
psmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public void delete(HttpServletRequest request) {
String sd = "C://12월국비//JSP//day24_//src//main//webapp//image";
int filesize = 1024*1024*10;
String encType = "utf-8";
MultipartRequest multi;
try {
multi = new MultipartRequest(
request,sd,filesize,encType);
int dnum = Integer.parseInt(multi.getParameter("num"));
String sql = "delete from db02171 where num =?";
try {
psmt = con.prepareStatement(sql);
psmt.setInt(1, dnum);
psmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
} catch (IOException e1) {
e1.printStackTrace();
}
}
public ArrayList<BookDTO> search(HttpServletRequest request) {
String item = request.getParameter("item");
String value = request.getParameter("value");
String sql = "select * from db02171 where "+item+" like ?";
try {
psmt = con.prepareStatement(sql);
psmt.setString(1, '%'+value+'%');
rs = psmt.executeQuery();
while(rs.next()) {
int num = rs.getInt(1);
String day = rs.getString(2).substring(0, 10);
String bookname = rs.getString(3);
String writer = rs.getString(4);
int price = rs.getInt(5);
String bigo = rs.getString(6);
String cover = rs.getString(7);
BookDTO dto = new BookDTO();
dto.setNum(num);
dto.setDay(day);
dto.setBookname(bookname);
dto.setWriter(writer);
dto.setPrice(price);
dto.setBigo(bigo);
dto.setCover(cover);
list.add(dto);
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
}
오라클 연결
datasource 이용
package com.ezen;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.http.HttpServletRequest;
import javax.sql.DataSource;
import com.oreilly.servlet.MultipartRequest;
public class BookDAO {
Connection con;
PreparedStatement psmt;
ResultSet rs;
DataSource ds;
ArrayList<BookDTO> list = new ArrayList<BookDTO>();
public BookDAO() throws NamingException {
Context context = new InitialContext();
ds = (DataSource)context.lookup("java:comp/env/jdbc/oracle11g");
try {
con = ds.getConnection();
} catch (SQLException e) {
e.printStackTrace();
}
}
public void insert(HttpServletRequest request) {
String sd = "C://12월국비//JSP//day24_//src//main//webapp//image";
int filesize = 1024*1024*10;
String encType = "utf-8";
try {
MultipartRequest multi = new MultipartRequest(
request,sd,filesize,encType);
// int num = Integer.parseInt(multi.getParameter("num"));
// String day = multi.getParameter("day");
String bookname = multi.getParameter("bookname");
String writer = multi.getParameter("writer");
int price = Integer.parseInt(multi.getParameter("price"));
String bigo = multi.getParameter("bigo");
String cover = multi.getFilesystemName("cover");
// String sql = "insert into db02171 values (?,?,?,?,?,?,?)";
String sql = "insert into db02171 values (BNUM_SEQ.nextval,sysdate,?,?,?,?,?)";
try {
psmt = con.prepareStatement(sql);
// psmt.setInt(1, num);
// psmt.setString(2, day);
// psmt.setString(3, bookname);
// psmt.setString(4, writer);
// psmt.setInt(5, price);
// psmt.setString(6, bigo);
// psmt.setString(7, cover);
psmt.setString(1, bookname);
psmt.setString(2, writer);
psmt.setInt(3, price);
psmt.setString(4, bigo);
psmt.setString(5, cover);
psmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public ArrayList<BookDTO> out() {
String sql = "select * from db02171";
try {
psmt = con.prepareStatement(sql);
rs = psmt.executeQuery();
while(rs.next()) {
int num = rs.getInt(1);
String day = rs.getString(2).substring(0, 10);
String bookname = rs.getString(3);
String writer = rs.getString(4);
int price = rs.getInt(5);
String bigo = rs.getString(6);
String cover = rs.getString(7);
BookDTO dto = new BookDTO();
dto.setNum(num);
dto.setDay(day);
dto.setBookname(bookname);
dto.setWriter(writer);
dto.setPrice(price);
dto.setBigo(bigo);
dto.setCover(cover);
list.add(dto);
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
public void modify(HttpServletRequest request) {
String sd = "C://12월국비//JSP//day24_//src//main//webapp//image";
int filesize = 1024*1024*10;
String encType = "utf-8";
try {
MultipartRequest multi = new MultipartRequest(
request,sd,filesize,encType);
int num = Integer.parseInt(multi.getParameter("num"));
String day = multi.getParameter("day");
String bookname = multi.getParameter("bookname");
String writer = multi.getParameter("writer");
int price = Integer.parseInt(multi.getParameter("price"));
String bigo = multi.getParameter("bigo");
String cover = multi.getFilesystemName("cover");
String sql = "update db02171 set day=?,writer=?,price=?,bigo=?,"
+ "cover=? where num=? and bookname=?";
try {
psmt = con.prepareStatement(sql);
psmt.setString(1, day);
psmt.setString(2, writer);
psmt.setInt(3, price);
psmt.setString(4, bigo);
psmt.setString(5, cover);
psmt.setInt(6, num);
psmt.setString(7, bookname);
psmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public void delete(HttpServletRequest request) {
String sd = "C://12월국비//JSP//day24_//src//main//webapp//image";
int filesize = 1024*1024*10;
String encType = "utf-8";
MultipartRequest multi;
try {
multi = new MultipartRequest(
request,sd,filesize,encType);
int dnum = Integer.parseInt(multi.getParameter("num"));
String sql = "delete from db02171 where num =?";
try {
psmt = con.prepareStatement(sql);
psmt.setInt(1, dnum);
psmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
} catch (IOException e1) {
e1.printStackTrace();
}
}
public ArrayList<BookDTO> search(HttpServletRequest request) {
String item = request.getParameter("item");
String value = request.getParameter("value");
String sql = "select * from db02171 where "+item+" like ?";
try {
psmt = con.prepareStatement(sql);
psmt.setString(1, '%'+value+'%');
rs = psmt.executeQuery();
while(rs.next()) {
int num = rs.getInt(1);
String day = rs.getString(2).substring(0, 10);
String bookname = rs.getString(3);
String writer = rs.getString(4);
int price = rs.getInt(5);
String bigo = rs.getString(6);
String cover = rs.getString(7);
BookDTO dto = new BookDTO();
dto.setNum(num);
dto.setDay(day);
dto.setBookname(bookname);
dto.setWriter(writer);
dto.setPrice(price);
dto.setBigo(bigo);
dto.setCover(cover);
list.add(dto);
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
}
package com.ezen;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("*.do")
public class FrontController extends HttpServlet {
private static final long serialVersionUID = 1L;
public FrontController() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String uri = request.getRequestURI();
String path = request.getContextPath();
String fname = uri.substring(path.length());
service service = null;
String vpage = null;
if(fname.equals("/input.do")) {
service = new Input();
service.aaa(request, response);
vpage="index.jsp";
}
if(fname.equals("/out.do")) {
service = new Out();
service.aaa(request, response);
vpage="out.jsp";
}
if(fname.equals("/modify.do")) {
service = new Modify();
service.aaa(request, response);
vpage="index.jsp";
}
if(fname.equals("/delete.do")) {
service = new Delete();
service.aaa(request, response);
vpage="index.jsp";
}
if(fname.equals("/search.do")) {
service = new Search();
service.aaa(request, response);
vpage="searchout.jsp";
}
if(fname.equals("/member.do")) {
service = new Member();
service.aaa(request, response);
vpage="index.jsp";
}
if(fname.equals("/login.do")) {
service = new Login();
service.aaa(request, response);
vpage=(String)request.getAttribute("vpage");
}
if(fname.equals("/logout.do")) {
service = new Logout();
service.aaa(request, response);
vpage="index.jsp";
}
if(fname.equals("/bookinput.do")) {
service = new BookInput();
service.aaa(request, response);
vpage="index.jsp";
}
if(fname.equals("/bookout.do")) {
service = new BookOut();
service.aaa(request, response);
vpage="bookout.jsp";
}
if(fname.equals("/bookmodify.do")) {
service = new BookModify();
service.aaa(request, response);
vpage="index.jsp";
}
if(fname.equals("/bookdelete.do")) {
service = new BookDelete();
service.aaa(request, response);
vpage="index.jsp";
}
if(fname.equals("/booksearch.do")) {
service = new BookSearch();
service.aaa(request, response);
vpage="booksearchout.jsp";
}
RequestDispatcher rd = request.getRequestDispatcher(vpage);
rd.forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
'JSP' 카테고리의 다른 글
230216_서블릿 (0) | 2023.02.16 |
---|---|
230215_서블릿 (0) | 2023.02.15 |
230214_서블릿 (0) | 2023.02.14 |
230213_서블릿 (0) | 2023.02.13 |
230210_서블릿 (0) | 2023.02.10 |
댓글