W3schools - JSP_Database
이 페이지는 다음에 대한 공부 기록입니다
Lecture에서 배웠던 내용을 복습하며 작성했습니다
찾으시는 정보가 있으시다면
주제별reference를 이용하시거나
우측 상단에 있는 검색기능을 이용해주세요
DataBase Access
Before starting with database access through a JSP, make sure you have proper JDBC environment setup along with a database
<%@ page import = “java.io.*, java.util.*, java.sql.*”%>
<%@ page import = “javax.servelt.http.*, javax.servlet.*”%>
<%@ taglib uri = “http://java.sun.com/jsp/jstl/core” prefix = “c”%>
<%@ taglib uri = “http://java.sun.com/jsp/jstl/sql” prefix = “sql”%>
<html>
<head>
<title>DELETE Operation</title>
</head>
<body>
<sql:setDataSource var = “snapshot” driver = “com.mysql.jdbc.Driver”
url = “jdbc:mysql://localhost/TEST”
user = “admin” password = “pass123”/>
<c:set var = “empId” value = “103”>
<sql:update dataSource = “${snapshot}” var = “count”>
DELETE FROM Employees WHERE Id = ?
<sql:param value = “${empId}”/>
</sql:update>
<sql:query dataSource = “${snapshot}” var = “result”>
SELECt * from Employees;
</sql;query>
<c:forEach var = “row” items = “${result.rows}”>
<div>
<span><c:out value = “${row.id}”/>\t</span>
<span><c:out value = “${row.first}”/>\t</span>
<span><c:out value = “${row.last}”/>\t</span>
<span><c:out value = “${row.age}”/>\t</span>
</div>
</c:forEach>
</body>
</html>