본문 바로가기
Spring/JSP

[JSP] JDBC 데이터노출

by JJH0100 2022. 11. 22.
728x90
반응형

필요한 사전 작업

테이블 생성

2022.11.22 - [Database] - [MySQL] 테이블생성, 사용해보기

 

[MySQL] 테이블생성, 사용해보기

2022.11.22 - [JSP] - [JSP] MySQL 설치 [JSP] MySQL 설치 https://www.mysql.com/ MySQL Over 2000 ISVs, OEMs, and VARs rely on MySQL as their products' embedded database to make their applications, hardware and appliances more competitive, bring them to ma

jjh93.com

JDBC연결

2022.11.22 - [JSP] - [JSP] mysql-connector-j-8.0.31 설치

 

[JSP] mysql-connector-j-8.0.31 설치

https://www.mysql.com/ MySQL Over 2000 ISVs, OEMs, and VARs rely on MySQL as their products' embedded database to make their applications, hardware and appliances more competitive, bring them to market faster, and lower their cost of goods sold. Learn More

jjh93.com

 

MemberTest.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%!
	Connection conn = null;
	Statement stmt = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	
	//선언
	String url = "jdbc:mysql://localhost:3306/mydb";
	String id = "root";
	String pw = "1234";
	String sql =  "select * from member";
%>
<table width="800" border="1">
	<tr>
		<th>이름</th>
		<th>아이디</th>
		<th>암호</th>
		<th>이메일</th>
	</tr>
	<!-- 스크립트 릿 -->
	<%
		try{
			//연동
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection(url, id, pw);
			stmt = conn.createStatement();
			rs = stmt.executeQuery(sql);
			while(rs.next()){
				out.println("<tr>");
				out.println("<td>" + rs.getString("name") + "</td>");
				out.println("<td>" + rs.getString("userid") + "</td>");
				out.println("<td>" + rs.getString("pwd") + "</td>");
				out.println("<td>" + rs.getString("email") + "</td>");
				out.println("</tr>");
			}
		}catch(Exception e){
			
		}
	%>
</table>
</body>
</html>

728x90
반응형

'Spring > JSP' 카테고리의 다른 글

[JSP] Apache Commons Library  (2) 2022.11.23
[JSP] JDBC 데이터 입력  (0) 2022.11.22
[JSP] mysql-connector-j-8.0.31 설치  (0) 2022.11.22
[JSP] 자바빈즈 (Java Beans)  (0) 2022.11.22
[JSP] 세션(Session)을 사용한 로그인과 로그아웃  (0) 2022.11.21

댓글