Connection Polling(커넥션 폴링) -OracleDB,H2DB

2019. 4. 5. 15:24JavaScript

#1 context.xml 추가하기

- WebContent/META-INF 에서 생성 및 dbcp.jar 추가

- tomcat-dbcp.jar의 위치

<?xml version="1.0" encoding="UTF-8"?>

<Context>

<Resource name="jdbc/OracleDB"

auth="Container"

type="javax.sql.DataSource"

username="scott"

password="tiger"

driverClassName="oracle.jdbc.OracleDriver"

url="jdbc:oracle:thin:@localhost:1521:xe"

factory="org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory"

maxActive="500"

maxIdle="100" />

</Context>

 

#2 OracleDB.java => 오라클서버를 연결하는 클래스

**** 오라클 드라이버 확인하기

CF) H2DB에서 Connection poll 

#3 JSP에서 사용하기 

<%@page import="dao.OracleDB"%>

<%@page import="java.sql.Connection"%>

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

pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

</head>

<body>

<%

Connection con = OracleDB.getConnection();

 

OracleDB.closeJDBC(con, null, null);

%>

연결 확인

</body>

</html>