========================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==============

+ Recent posts