본문 바로가기

기존카테고리/Java & jsp Tip

글자변환(String Replace) 과 날짜 표시 (변환?)

글자 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>