1. JSTL SQL QUERY Test


create table student(

id varchar2(20) not null,

passwd varchar2(20) not null,

name varchar2(20) not null,

year number(4) null,

snum varchar2(10) null,

depart varchar2(30) null,

mobile1 varchar2(4) null,

mobile2 varchar2(10) null,

address varchar2(65) null,

email varchar2(30) null,

PRIMARY KEY(id) );



insert into student (id, passwd, name, year, snum, depart, mobile1, mobile2, address, email) 

values ('javajsp', 'java8394', '수선화', 2010, '1077818', '컴퓨터공학과', '011', '7649-9875', '서울시', 'java2@gmail.com');


insert into student (id, passwd, name, year, snum, depart, mobile1, mobile2, address, email) 

values ('gonji', 'young', '백일홍', 2009, '2065787', '인터넷비즈니스과', '016', '2975-9854', '인천시', 'gong@hotmail.com');


insert into student (id, passwd, name, year, snum, depart, mobile1, mobile2, address, email) 

values ('water', 'javayoung', '수국', 2010, '1176432', '기술경영과', '011', '5531-6677', '제주도', 'singer@gmail.com');


insert into student (id, passwd, name, year, snum, depart, mobile1, mobile2, address, email) 

values ('novel', 'elephant', '백합', 2011, '2056485', '컴퓨터공학과', '016', '3487-9919', '서울시', 'novel@hanmail.com');


insert into student (id, passwd, name, year, snum, depart, mobile1, mobile2, address, email) 

values ('korea', '9943inner', '해당화', 2010, '1987372', '기술경영과', '017', '2670-4593', '인천시', 'wing@gmail.com');



<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>JSTL SQL QUERY Test</title>

</head>

<body>


<h2>JSTL SQL TAG : setDataSource , query , param</h2>


<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<hr size="5" color="green">

<h2> 전체 학생 조회 </h2>


<sql:setDataSource var="stuDS" dataSource="jdbc/OracleDB"/>

<sql:query var="studentsRS" dataSource="${stuDS}">

SELECT * FROM student

</sql:query>


<sql:query var="studentsRS" dataSource="${stuDS}" sql="SELECT * FROM student"/>


<c:forEach var="studentRow" begin="0" items="${studentsRS.rows}">

${studentRow.id},${studentRow.passwd},${studentRow.name},${studentRow.depart}<br>

</c:forEach>


<hr size="5" color="orange">

<h2>컴퓨터공학과 학생 조회</h2>


<sql:query var="comRS" dataSource="${stuDS}">

SELECT * FROM student where year = ? and depart = ?

<sql:param value="2010"/> <sql:param value="컴퓨터공학과"/>

</sql:query>


<c:forEach var="studentRow" begin="0" items="${comRS.rows}">

${studentRow.id},${studentRow.passwd},${studentRow.name},${studentRow.depart},${studentRow.year}<br>

</c:forEach>



<hr size="5" color="cyan">


<c:forEach var="studentRow" begin="0" items="${comRS.rowsByIndex}">

${studentRow[0]},${studentRow[1]},${studentRow[2]},${studentRow[5]}<br>

</c:forEach>

<hr size="5" color="red">


</body>

</html>



2. JSTL SQL TAG : update, dataParam


<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>JSTL SQL TAG : update, dataParam</title>

</head>

<body>


<h2>JSTL SQL Tag : update, dateParam</h2>


<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<hr size="5" color="green">

<h2> 전체 게시판 조회 </h2>


<sql:setDataSource var="ds" dataSource="jdbc/OracleDB"/>


<sql:query var="rs" dataSource="${ds}" sql="select * from student"/>


<c:forEach var="studentRow" begin="0" items="${rs.rows}">

${studentRow.id},${studentRow.passwd},${studentRow.name},${studentRow.depart},${studentRow.address},${studentRow.year}<br>

</c:forEach>


<hr size="5" color="orange">

<h3> 이름 "수선화" 인 레코드에서 주소를 "수원시"로 입학년도를 2017 로 변경 </h3>


<sql:update var="nn" dataSource="${ds}">


UPDATE student SET address = ?, year = ? WHERE name = ?

<sql:param value="수원시"/>

<sql:param value="2017"/>

<sql:param value="수국"/>

</sql:update>


<hr size="5" color="blue">

<h2> 게시판 다시 전체 조회 </h2>


<sql:query var="rs" dataSource="${ds}" sql="select * from student"/>


<c:forEach var="studentRow" begin="0" items="${rs.rows}">

${studentRow.id},${studentRow.passwd},${studentRow.name},${studentRow.depart},${studentRow.address},${studentRow.year}<br>

</c:forEach>


<hr size="5" color="cyan">

<hr size="5" color="red">


</body>

</html>



3. JSTL SQL TAG : function Test


<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>JSTL SQL TAG : function Test</title>

</head>

<body>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>


<h2> JSTL SQL TAG : function </h2>


<hr size="5" color="green">


<c:set var="addr" value=" http://www.daum.net "/>

\${addr} = "${addr}"<br>

\${fn:length(addr) } = ${fn:length(addr) }<br>

\${fn:toUpperCase(addr)} = "${fn:toUpperCase(addr)}"<br>


\${fn:substring(addr,15,20)} = "${fn:substring(addr,15,20) }"<br>

\${fn:substringBefore(addr,":")} = "${fn:substringBefore(addr,":") }"<br>

\${fn:substringAfter(addr,"//")} = "${fn:substringAfter(addr,"//")}"<p>


\${fn:trim(addr)} = "${fn:trim(addr)}"<br>

\${fn:replace(addr,"net","com" } = ${fn:replace(addr,"net","com")}<br>

\${fn:indexOf(addr,":")} = ${fn:indexOf(addr,":") }<p>


\${fn:startsWith(addr,"http") } = ${fn:startsWith(addr,"http") }<br>

\${fn:endsWith(addr,"t") } = ${fn:endsWith(addr,"t") }<br>

\${fn:contains(addr,"www") } = ${fn:contains(addr,"www") }<br>

\${fn:containsIgnoreCase(addr,"KR") } = ${fn:containsIgnoreCase(addr,"KR") }<br>

<hr size="5" color="red">


</body>

</html>

+ Recent posts