1. Connection pool 라이브러리, HikariCP
- HikariCP
- 다운로드 : https://mvnrepository.com/artifact/com.zaxxer/HikariCP/4.0.3
- SLF4J API
- 다운로드 : https://mvnrepository.com/artifact/org.slf4j/slf4j-api/1.7.36
2. HikariCP 사용방법
- DBConn.java
package utils;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
public class DBConn {
@SuppressWarnings("resource")
public static Connection getConnection() throws SQLException, ClassNotFoundException {
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setDriverClassName("oracle.jdbc.driver.OracleDriver");
hikariConfig.setJdbcUrl("jdbc:oracle:thin:@localhost:1521/xe");
hikariConfig.setUsername("HR");
hikariConfig.setPassword("1234");
Connection conn = new HikariDataSource(hikariConfig).getConnection();
return conn;
}
}
- 계정 연결 확인
public static void main(String[] args) throws Exception {
System.out.println(getConnection());
}
- 데이터 입력하기(계정 내에 있는 프로시저 사용)
public static void main(String[] args) throws Exception {
CallableStatement cstmt = getConnection().prepareCall("{call proc_test(?)}");
cstmt.setString(1, "javamail3");
cstmt.executeUpdate();
}