간단하게 
 MySQL을 이용하여 테이블을 구성하겠습니다.

* 개발 도구 (개발 환경)
eclipse EE, jdk1.7, Tomcat7.0, MySQL5.5

* MySQL
MySQL 사용자: root
MySQL 비밀번호: admin 
데이터베이스 명: test
테이블 명: jsp 
칼럼: id varchar(20), password varchar(20) 

 
 - 아래 그림은 설정된 MySQL 정보를 보여줍니다. 아래와 같이 데이터가 입력된 상태로 시작하겠습니다.



좋은 글이면 손가락 눌러 주세요. 힘이 됩니다 ^^ 

로그인이 필요 없습니다.




* read_DB.jsp




<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Read Database Page</title>
</head>
<body>
<%@ page import = "java.sql.*, java.util.*" %>
MySQL 데이터 읽기
<%
Class.forName("com.mysql.jdbc.Driver");
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "admin");
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from jsp");
%>
<br><br>----------------------------------------<br>
<% while(rs.next()) { %>
<br> ID: <%= rs.getString("id") %><br>
<br> Password: <%=rs.getString("password") %><br>
--------------------------------------------<br><br>
<%
}catch (SQLException e) { %>
<% e.printStackTrace(); %>
<%
} finally {
if(rs!=null)
try {
rs.close();
} catch (SQLException e) {}
if(stmt!=null)
try {
stmt.close();
} catch (SQLException e) {}
if(conn!=null)
try {
conn.close();
} catch (SQLException e) {}
}
%>
</body>
</html> 




* 결과 화면
 







posted by 쪼재