2022.09.21
// https://docs.oracle.com/cd/E13222_01/wls/docs81/ConsoleHelp/jdbc_connection_pools.html
// https://www.oracle.com/java/technologies/front-controller.html
"update board set title=? author=? email=? content=? num=? pw=?
// step04
@WebServlet(urlPatterns = {"/var"}, initParams = {@WebInitParam(name = "charset", value = "UTF-8")})
// JSTL 조건문
<h2>JSTL</h2>
<h3>step01 : Condition</h3>
<c:if test="${'a' == 'a'}">
조건이 참이라면 실행되는 영역
</c:if>
<br><hr><br>
<%-- empty 활용하여 null 검증하기 --%>
<% request.setAttribute("customer", null); %>
<c:if test="${not empty requestScope.customer}">
null일때에는 실행되지 않는 영역
</c:if>
<br><hr><br>
<%-- 다중 조건 : choose, when --%>
<% session.setAttribute("goal", 4); %>
<c:choose>
<c:when test="${sessionScope.goal == 2}">
멀티!
</c:when>
<c:when test="${sessionScope.goal == 3}">
헤트트릭!
</c:when>
<c:otherwise>
해당 조건이 없을때 실행 영역
</c:otherwise>
</c:choose>
// model.domain 이름, 나이 출력
<%
ArrayList users = new ArrayList();
users.add(new User("IT", 26));
users.add(new User("DEV", 30));
session.setAttribute("users", users);
%>
<c:forEach items="${sessionScope.users}" var="data" varStatus="LoopStatus">
${LoopStatus.count}번 데이터 - 이름 : ${data.name} 나이 : ${data.age} <br>
</c:forEach>
DB 시스템의 동시 접속자 수를 강제적으로 제한 하는 기술
적용 방법
원리
적용 기술
context.xml
<Resource
name="jdbc/mysql" - 설정 정보를 구분하기 위한 고유한 자원의 별칭
auth="Container" - 이 자원의 관리 권한은 container 즉 서버가 관리 함을 의미
type="javax.sql.DataSource" - 자바 소스와 서버 설정 정보의 중간 매개체 객체 타입
driverClassName="com.mysql.cj.jdbc.Driver" - oracle DB driver 지정
url="jdbc:mysql://localhost:3306/scott" - oracle 접속을 위한 url 설정
username="" - ID
password="" - PW
maxTotal="20" - 동시 접속 max Connection 개수
maxIdle="10" - 10개의 객체는 늘 대기 개수
maxWaitMillis="-1" /> - 20개 초과한 대기 시간, -1 따라서 무한 대기의미
// DBUtil
// 1단계 : Driver 로딩
static {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
// 2단계 : DB 연결 가능 메소드
public static Connection getConnection() throws SQLException {
// return DriverManager.getConnection("jdbc:mysql://localhost:3306/scott?serverTimezone=Asia/Seoul", "scott", "tiger");
return DriverManager.getConnection("jdbc:mysql://mysql-test.cdijggtrxo14.us-east-1.rds.amazonaws.com:3306/scott", "root", "root1234");
}
// 6단계 : 자원반환 메소드
public static void close(ResultSet rset, Statement stmt, Connection con) throws SQLException {
if(rset != null) {
rset.close();
}
if(stmt != null) {
stmt.close();
}
if(con != null) {
con.close();
}
}
public static void close(Statement stmt, Connection con) throws SQLException {
if(stmt != null) {
stmt.close();
}
if(con != null) {
con.close();
}
}
public static String getDnameByDeptno(int deptno) q {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rset = null;
String sql = "SELECT dname FROM DEPT WHERE deptno = ?";
String dname = null;
try {
con = DBUtil.getConnection();
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, deptno);
rset = pstmt.executeQuery();
if(rset.next()) {
dname = rset.getString("dname");
}
} finally {
DBUtil.close(rset, pstmt, con);
}
return dname;
}
package model;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import util.DBUtil;
public class DeptDAO {
//deptno로 dname 검색
//Query : "SELECT dname FROM DEPT WHERE deptno = ?"
public static String getDnameByDeptno(int deptno) throws SQLException {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rset = null;
String sql = "SELECT dname FROM DEPT WHERE deptno = ?";
String dname = null;
try {
con = DBUtil.getConnection();
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, deptno);
rset = pstmt.executeQuery();
if(rset.next()) {
dname = rset.getString("dname");
}
} finally {
DBUtil.close(rset, pstmt, con);
}
return dname;
}
}
data - > DB 구축
Write.html -> 값을 입력
list.jsp -> 입력된 값을 확인
게시글 제목 클릭
-> 해당게시글 상세페이지
-> 수정하기 위한 목적
-> 직접 데이터를 수정
-> 수정하기 버튼 클릭
-> Update , 삭제