Notice
Recent Posts
Recent Comments
Link
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

chapter06 : view_all 본문

JSP/DB (2)

chapter06 : view_all

GAWON 2023. 5. 24. 18:58
<%@page import="org.joonzis.db.DBConnect"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@ 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>
</head>
<body>
	<jsp:include page="index.jsp"/>
	
	<br><hr><br>
	
	<%
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
	
		try {
			conn = DBConnect.getConnection();
			String sql ="select * from member"; 
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
	%>

		<h1>member 테이블의 전체 데이터</h1>
		<table>
			<thead>
				<tr>
					<th>회원 번호</th>
					<th>아이디</th>
					<th>비밀번호</th>
					<th>이름</th>
					<th>나이</th>
					<th>주소</th>
					<th>가입일</th>
				</tr>
			</thead>		
		<tbody>
			<%
				if(!rs.next()){%>
				<tr>
					<td colspan="7">member가 없습니다.</td>
				</tr>		
				<%}else{
					do{%>
						<tr>
							<td><%=rs.getInt(1) %></td>
							<td><%=rs.getString(2) %></td>
							<td><%=rs.getString(3) %></td>
							<td><%=rs.getString(4) %></td>
							<td><%=rs.getInt(5) %></td>
							<td><%=rs.getString(6) %></td>
							<td><%=rs.getDate(7) %></td>
						</tr>	
				<%}while(rs.next());
				}
			%>
		</tbody>
	</table>	
	
	<%		
			
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (rs != null) {
					rs.close();
				}
				if (ps != null) {
					ps.close();
				}
				if (conn != null) {
					conn.close();
				}
	
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
		
		
	%>
	
</body>
</html>

'JSP > DB (2)' 카테고리의 다른 글

chapter07 : view_one  (0) 2023.05.24
chapter05 : update  (0) 2023.05.24
chapter04 : update_one  (0) 2023.05.24
chapter03 : remove_one  (0) 2023.05.24
chapter02 : insert_one  (0) 2023.05.24