728x90
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import = "java.sql.DriverManager" %>
<%@ page import = "java.sql.Connection" %>
<%@ page import = "java.sql.PreparedStatement" %>
<%@ page import = "java.sql.ResultSet" %>
<%@ page import = "java.sql.SQLException" %>
<%= request.getRequestURI() %> <br>
회원 리스트 <br>
<table width="100%" border = "1">
<tr>
<td>아이디</td><td>비번</td><td>권한</td><td>이름</td><td>이메일</td>
</tr>
<%
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
Class.forName("com.mysql.jdbc.Driver");
try{
String jdbcDriver = "jdbc:mysql://localhost:3306/db03yyj?" +
"useUnicode=true&characterEncoding=euckr";
String dbUser = "dbid03yyj";
String dbPass = "dbpw03yyj";
conn = DriverManager.getConnection(jdbcDriver, dbUser, dbPass);
System.out.println(conn + " <-- conn user_list.jsp");
if(conn != null){
out.println("01 DB연결 성공");
}else{
out.println("02 DB연결 실패");
}
pstmt = conn.prepareStatement("select * from tb_user");
rs = pstmt.executeQuery();
System.out.println(rs + " <-- rs user_list.jsp");
//System.out.println(rs.next() + " <- rs.next() user_list.jsp");
while(rs.next()){
%>
<tr>
<td><%= rs.getString(1) %></td>
<td><%= rs.getString(2) %></td>
<td><%= rs.getString(3) %></td>
<td><%= rs.getString(4) %></td>
<td><%= rs.getString(5) %></td>
</tr>
<%
}
} catch(SQLException ex){
out.println(ex.getMessage());
ex.printStackTrace();
} finally{
if(rs != null) try{ rs.close();} catch(SQLException ex){}
if(pstmt != null) try { pstmt.close();}catch(SQLException ex){}
if(conn != null) try{ conn.close();}catch(SQLException ex){}
}
%>
</table>
반응형
'Backend > JAVA' 카테고리의 다른 글
jdbc - 검색하기 (0) | 2020.03.27 |
---|---|
jdbc update 쿼리 실행 (0) | 2020.03.26 |
jsp -db 연결 중 error (0) | 2020.03.19 |
JAVA 화면 연동 기초 이해하기 (0) | 2020.03.12 |
java - 하나의 package 내, 여러 개의 클래스 내 method 선언하기 2 (0) | 2020.03.03 |
댓글