Create table guest (
custno number(6) not null primary key ,
custname varchar2(20),
phone varchar2(13),
address varchar2(60),
joindate date
);
//테이블 만들기
CREATE SEQUENCE guest_idx INCREMENT BY 1 START WITH 1;
//시퀀스 만들기
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<% request.setCharacterEncoding("UTF-8"); %>
<%@ include file ='dbconn.jsp' %>
<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%
SimpleDateFormat format1
= new SimpleDateFormat ("yyyyMMdd");
Date time = new Date();
String time1 = format1.format(time);
try{
for (int i=1 ; i < 10000; i++ ) {
String k1[] = {"하니","둘리","똘이","영심이","철이", "하늘이","지효","지솔","JYP","빅히트" };
String k21[] = {"010","011","019","017","016", "02","055","054","056","070" };
String k22[] = {"1111","2222","3333","4444","5555", "6666","7777","8888","9999","1010" };
String k23[] = {"9001","1234","2323","5436","6677", "6576","9987","9573","3425","7527" };
String k3[] = {"서울","경기","인천","제주도","홍콩", "필리핀","일본","중국","베트남","캐나다" };
int ch1=(int)(Math.random() * 10 );
int ch21=(int)(Math.random() * 10 );
int ch22=(int)(Math.random() * 10 );
int ch23=(int)(Math.random() * 10 );
int ch3=(int)(Math.random() * 10 );
sql = " insert into guest ";
sql = sql + " (custno, custname, phone, address, joindate ) " ;
sql = sql + " values(guest_idx.nextval,?,?,?,?) ";
pstmt = con.prepareStatement(sql);
pstmt.setString(1, k1[ch1] );
pstmt.setString(2, k21[ch21]+"-" +k22[ch22]+"-"+k23[ch23]);
pstmt.setString(3, k3[ch3]);
pstmt.setString(4, time1);
pstmt.executeUpdate();
pstmt.close();
}
} catch (Exception e) {
e.printStackTrace();
} finally{
con.close();
}
%>
SELECT ROWNUM, P.*
FROM(
(SELECT ROWNUM AS RN, K.*
FROM(
SELECT * FROM GUEST
ORDER BY CUSTNO DESC)K
WHERE ROWNUM <= 30
)P
) WHERE RN >= 10 ;
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
String path = request.getContextPath();
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<div align="center" >
<a href="<%=path%>/BigListController">화면출력</a>
<table id =table2 border=1 >
<tr><td>ROWNUM</td><td>RN</td><td>번호</td><td>이름 </td><td> 전화</td><td>주소 </td>
<td>가입날짜 </td><td>고객등급 </td><td>거주도시 </td></tr>
<c:forEach var='m' items="${list}">
<tr>
<td>${m.custno}</td>
<td>${m.rownum}</td>
<td>${m.rn}</td>
<td>${m.custname}</td>
<td>${m.phone}</td>
<td>${m.address}</td>
<td>${fn:substring(m.joindateS,0,10)}</td>
<td>${m.grade}</td>
<td>${m.city}</td>
</tr>
</c:forEach>
</table>
</div>
</body>
</html>
package service;
import java.util.List;
import dao.BigListDaoImpl;
import model.guestVo;
public class BigListServiceImpl {
BigListDaoImpl dao = new BigListDaoImpl();
public List<guestVo> selectAll(guestVo g){
return dao.selectAll(g);
}
}
package dao;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import conn.DBConn;
import model.guestVo;
public class BigListDaoImpl {
DBConn db = DBConn.getInstance();
Connection con = null;
String sql = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<guestVo> list = null;
public List<guestVo> selectAll(guestVo g){
list = new ArrayList<guestVo>();
try {
con = db.getConnect();
sql = "select rownum, p.* from " ;
sql = sql + " (select rownum as rn, k.* from ";
sql = sql + " (select * from guest order by custno desc)k ";
sql = sql + " where rownum <= ? " ;
sql = sql + " )p where rn >= ? ";
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, 30);
pstmt.setInt(2, 21);
rs = pstmt.executeQuery();
while(rs.next()) {
g = new guestVo();
g.setRownum(rs.getInt("rownum"));
g.setRn(rs.getInt("rn"));
g.setCustno(rs.getInt("custno"));
g.setCustname(rs.getString("custname"));
g.setPhone(rs.getString("phone"));
g.setAddress(rs.getString("address"));
g.setJoindate(rs.getString("joindate"));
list.add(g);
}
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
}