카테고리 없음
jstl 로 SQL 만지기
🩷 슈 🧡
2010. 7. 8. 21:46
728x90
SMALL
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!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=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<fmt:requestEncoding value="euc-kr" />
<h2>SQL 태그연습</h2>
<div>이름은 ${param.name }</div>
<fieldset>
<legend>이름넣기</legend>
<form method="post" action="">
Name : <input type="text" name="name" />
<input type="submit" value="가자" />
</form>
</fieldset>
<c:catch var="msg"><!-- 예외처리용 -->
<!-- Connection 설정 -->
<sql:setDataSource
driver="oracle.jdbc.OracleDriver"
user="user01"
password="user01"
url="jdbc:oracle:thin:@211.241.228.11:1521:orcl"
var="con"
/>
<!-- 데이터입력 -->
<c:set var="name" value="${param.name}"/>
<sql:update dataSource="${con}">
insert into test2 values (test2_seq.nextval,?)
<sql:param value="${name }"></sql:param>
</sql:update>
<!-- 데이터조회 -->
<sql:query var="rs" dataSource="${con}">
select * from test2
</sql:query>
<!-- 꺼내자 -->
<c:forEach items="${rs.rows}" var="row">
${row['num']}, ${row['name']}<br/>
</c:forEach>
</c:catch>
<c:if test="${msg != null}">
${msg.message}
</c:if>
</body>
</html>
pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!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=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<fmt:requestEncoding value="euc-kr" />
<h2>SQL 태그연습</h2>
<div>이름은 ${param.name }</div>
<fieldset>
<legend>이름넣기</legend>
<form method="post" action="">
Name : <input type="text" name="name" />
<input type="submit" value="가자" />
</form>
</fieldset>
<c:catch var="msg"><!-- 예외처리용 -->
<!-- Connection 설정 -->
<sql:setDataSource
driver="oracle.jdbc.OracleDriver"
user="user01"
password="user01"
url="jdbc:oracle:thin:@211.241.228.11:1521:orcl"
var="con"
/>
<!-- 데이터입력 -->
<c:set var="name" value="${param.name}"/>
<sql:update dataSource="${con}">
insert into test2 values (test2_seq.nextval,?)
<sql:param value="${name }"></sql:param>
</sql:update>
<!-- 데이터조회 -->
<sql:query var="rs" dataSource="${con}">
select * from test2
</sql:query>
<!-- 꺼내자 -->
<c:forEach items="${rs.rows}" var="row">
${row['num']}, ${row['name']}<br/>
</c:forEach>
</c:catch>
<c:if test="${msg != null}">
${msg.message}
</c:if>
</body>
</html>
728x90
LIST