글자 char 변환:
String name=rs.getString("name"); //"홍길동"
name=name.replace("홍", "박"); //"박길동"
날짜 표시:
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<fmt:formatDate value="<%=rDate %>" pattern="yyyy-MM-dd" /> // "2017-06-28"
<fmt:formatDate value="<%=rDate %>" pattern="yyyy/MM/dd" /> // "2017/06/28"
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<table width=800 border=1>
<tr>
<td>아이디</td>
<td>비밀번호</td>
<td>이름</td>
<td>전화번호</td>
<td>주소</td>
<td>날짜</td>
<td>삭제</td>
</tr>
<%
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","scott","1234");
try{
String sql="select * from memberBook";
pstmt=conn.prepareStatement(sql);
rs=pstmt.executeQuery();
while(rs.next()){
String id=rs.getString("id");
String pw=rs.getString("pw");
String name=rs.getString("name");
String tel=rs.getString("tel");
String address=rs.getString("address");
Timestamp rDate=rs.getTimestamp("rDate");
name=name.replace("홍", "박");
%>
<tr>
<td><a href="updateForm.jsp?id=<%=id%>"><%=id %></a></td>
<td><%=pw %></td>
<td><%=name %></td>
<td><%=tel %></td>
<td><%=address %></td>
<td><fmt:formatDate value="<%=rDate %>" pattern="yyyy/MM/dd" /></td>
<td><a href="deleteForm.jsp?id=<%=id%>">삭제</a></td>
</tr>
<%
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(rs!=null) rs.close();
if(pstmt!=null) pstmt.close();
if(conn!=null) conn.close();
}
%>
</table>
<%
%>
</body>
</html>
'기존카테고리 > Java & jsp Tip' 카테고리의 다른 글
Spring에서 한글깨짐 방지를 위해 web.xml에서 한글 설정 (2) | 2017.07.18 |
---|---|
포워딩(Forwarding) - dispatcher, HttpServletResponse (0) | 2017.07.08 |
getContextPath 와 getRequestURI (0) | 2017.07.08 |
asp Response.end 또는 php의 exit;와 같은 jsp의 if(true) return; (0) | 2017.07.07 |
체크 박스 받기 (0) | 2017.07.06 |