========================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 MariaDBUtil {
public static Connection getConnection() throws Exception {
DataSource dataSource = (DataSource) new InitialContext().lookup("java:comp/env/jdbc_maria");
// 커넥션 연결 - 커넥션 풀에서 하나만 가져와서 커넥션 연결
return dataSource.getConnection();
}// end of getConnection()
// DB관련 객체를 닫는 메서드 - select
public static void close(Connection con, PreparedStatement pstmt, ResultSet rs) throws SQLException {
close(con, pstmt);
if (rs != null)
rs.close();
}// end of close(con,pstmt,rs)
// DB관련 객체를 닫는 메서드 - insert, update, delete
public static void close(Connection con, PreparedStatement pstmt) throws SQLException {
if (con != null)
con.close();
if (pstmt != null)
con.close();
}// end of close(con,pstmt)
}// end of class MariaDBUtil
========================Java========================
==============WebContent/META-INF/context.xml==============
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Context>
<Context>
<Resource
name = "jdbc_maria"
auth = "Container"
type = "javax.sql.DataSource"
driverClassName = "org.mariadb.jdbc.Driver"
username = "(아이디)"
password = "(비밀번호)"
maxActive="(최대 커넥션 갯수)"
maxIdle = "(최대 유지 갯수)"
url="jdbc:mysql://(IP)/(DB이름)"
/>
</Context>
==============WebContent/META-INF/context.xml==============
'데이터베이스' 카테고리의 다른 글
[Mybatis] pom.xml 자료(Oracle) (0) | 2018.05.20 |
---|---|
MongoDB에 계정(유저) 추가하기 (0) | 2018.04.17 |
Oracle 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 |