=====================Java=====================
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.naming.InitialContext;
import javax.sql.DataSource;
public class DBUtil {
// connection 객체를 전달해 주는 프로그램 작성 //2. 연결
public static Connection getConnection()
throws Exception {
DataSource dataSource
= (DataSource) new InitialContext()
.lookup("java:comp/env/jdbc/OracleDB");
return dataSource.getConnection();
}
// DB관련 객체를 닫는 메서드 - select
public static void close
(Connection con, PreparedStatement pstmt, ResultSet rs)
throws SQLException {
close(con,pstmt);
if(rs != null) rs.close();
}
// DB관련 객체를 닫는 메서드 - insert, update, delete
public static void close
(Connection con, PreparedStatement pstmt)
throws SQLException {
if(con != null) con.close();
if(pstmt != null) pstmt.close();
}
}
=====================Java=====================
===========WebContent/META-INF/context.xml===========
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Context>
<Context>
<Resource
name="jdbc/OracleDB"
auth="Container"
type="javax.sql.DataSource"
username="(아이디)"
password="(비밀번호)"
driverClassName="oracle.jdbc.driver.OracleDriver"
factory="org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory"
url="jdbc:oracle:thin:@(IP):(SID)"
initialSize = "(초기값)"
maxTotal="(최대 커넥션 갯수)"
maxIdle="(최대 유지값)"
minIdle="(최소 유지값)"
/>
</Context>
===========WebContent/META-INF/context.xml===========
'데이터베이스' 카테고리의 다른 글
MongoDB에 계정(유저) 추가하기 (0) | 2018.04.17 |
---|---|
MariaDB Connection Pool 자료 (Java) (0) | 2018.04.15 |
MongoDB Connection Pool 만들기 in Java 3 (0) | 2018.04.14 |
MongoDB Connection Pool 만들기 in Java 2 (0) | 2018.04.13 |
MongoDB Connection Pool 만들기 in Java 1 (0) | 2018.04.12 |