memberSelect.jsp
<%@page import="exx.MemberDTO"%>
<%@page import="exx.MemberDAO"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%
MemberDAO memberDAO = new MemberDAO();
ArrayList<MemberDTO> dtos = memberDAO.memberSelect();
for(int i=0;i<dtos.size(); i++){
MemberDTO dto = dtos.get(i);
String name = dto.getName();
String id = dto.getId();
String pw = dto.getPw();
String phone = dto.getPhone1()+"-"+dto.getPhone2()+"-"+dto.getPhone3();
String gender = dto.getGender();
out.println("이름:"+name+"아이디:"+id+",비밀번호:"+pw+",연락처:"+phone+",성별:"+gender+"<br/>");
}
%>
</body>
</html>
--------------------------------------------------------------------------------------
MemberDAO.java
package exx;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.apache.tomcat.jdbc.pool.DataSource;
public class MemberDAO {
private DataSource dataSource;
public MemberDAO() {
try {
}catch(Exception e) {
e.printStackTrace();
}
}
public ArrayList<MemberDTO> memberSelect(){
ArrayList<MemberDTO> dtos = new ArrayList<MemberDTO>();
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con =DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","scott","tiger");
stmt = con.createStatement();
rs = stmt.executeQuery("select *from member");
while(rs.next()) {
String name = rs.getString("name");
String id = rs.getString("id");
String pw = rs.getString("pw");
String phone1 = rs.getString("phone1");
String phone2 = rs.getString("phone2");
String phone3 = rs.getString("phone3");
String gender = rs.getString("gender");
MemberDTO dto = new MemberDTO(name,id,pw,phone1,phone2,phone3,gender);
dtos.add(dto);
}
}catch(Exception e) {
e.printStackTrace();
}finally {
try {
if(rs!=null) rs.close();
if(stmt!=null)stmt.close();
if(con!=null)con.close();
}catch(Exception e) {
e.printStackTrace();
}
}
return dtos;
}
}
------------------------------------------------------------------------------------
MemberDTO dto = new MemberDTO(name,id,pw,phone1,phone2,phone3,gender);
dtos.add(dto);
ArrayList에 add한다.