HikariCP Connection Pool 라이브러리 추가 및 테스트
- 라이브러리 추가 - 연결 테스트 -DataSourceTests.java
This commit is contained in:
@@ -123,6 +123,14 @@
|
||||
<artifactId>ojdbc8</artifactId>
|
||||
<version>19.3.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- HikariCP Connection pool -->
|
||||
<!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP -->
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>3.4.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Servlet -->
|
||||
<dependency>
|
||||
|
||||
@@ -4,6 +4,17 @@
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
|
||||
|
||||
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
|
||||
<property name="driverClassName" value="oracle.jdbc.pool.OracleDataSource"></property>
|
||||
<property name="jdbcUrl" value="jdbc:oracle:thin:@Localhost:1521:XE"></property>
|
||||
<property name="username" value="c##vam"></property>
|
||||
<property name="password" value="1234"></property>
|
||||
</bean>
|
||||
|
||||
<bean id="datasource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
|
||||
<constructor-arg ref="hikariConfig"></constructor-arg>
|
||||
</bean>
|
||||
|
||||
<context:component-scan base-package="com.vam.sample"></context:component-scan>
|
||||
|
||||
|
||||
35
VamPa/src/test/java/com/vam/persistence/JDBCTests.java
Normal file
35
VamPa/src/test/java/com/vam/persistence/JDBCTests.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package com.vam.persistence;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class JDBCTests {
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName("oracle.jdbc.driver.OracleDriver");
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnection() {
|
||||
|
||||
try(Connection con =
|
||||
DriverManager.getConnection(
|
||||
"jdbc:oracle:thin:@localhost:1521:XE",
|
||||
"c##vam",
|
||||
"1234")){
|
||||
System.out.println(con);
|
||||
}catch(Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
34
VamPa/src/test/java/com/vam/sample/DataSourceTests.java
Normal file
34
VamPa/src/test/java/com/vam/sample/DataSourceTests.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package com.vam.sample;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/root-context.xml")
|
||||
public class DataSourceTests {
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Test
|
||||
public void testConnection() {
|
||||
try(
|
||||
Connection con = dataSource.getConnection();
|
||||
){
|
||||
|
||||
System.out.println("con="+con);
|
||||
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
#Generated by Maven Integration for Eclipse
|
||||
#Sat Aug 08 00:05:22 KST 2020
|
||||
#Sat Aug 08 00:16:06 KST 2020
|
||||
version=1.0.0-BUILD-SNAPSHOT
|
||||
groupId=com.vam
|
||||
m2e.projectName=VamPa
|
||||
|
||||
@@ -123,6 +123,14 @@
|
||||
<artifactId>ojdbc8</artifactId>
|
||||
<version>19.3.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- HikariCP Connection pool -->
|
||||
<!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP -->
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>3.4.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Servlet -->
|
||||
<dependency>
|
||||
|
||||
@@ -117,6 +117,14 @@
|
||||
<version>8.0.18</version>
|
||||
</dependency>
|
||||
|
||||
<!-- HikariCP Connection pool -->
|
||||
<!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP -->
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>3.4.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- @Inject -->
|
||||
<dependency>
|
||||
<groupId>javax.inject</groupId>
|
||||
|
||||
@@ -5,6 +5,17 @@
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
|
||||
|
||||
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
|
||||
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"></property>
|
||||
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/ksj?serverTimezone=Asia/Seoul"></property>
|
||||
<property name="username" value="root"></property>
|
||||
<property name="password" value="1234"></property>
|
||||
</bean>
|
||||
|
||||
<bean id="datasource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
|
||||
<constructor-arg ref="hikariConfig"></constructor-arg>
|
||||
</bean>
|
||||
|
||||
<context:component-scan base-package="com.vam.sample"></context:component-scan>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.vam.persistence;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/root-context.xml")
|
||||
public class DataSourceTests {
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Test
|
||||
public void testConnection() {
|
||||
try(
|
||||
Connection con = dataSource.getConnection();
|
||||
){
|
||||
|
||||
System.out.println("con="+con);
|
||||
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
36
VamPa_MySQL/src/test/java/com/vam/persistence/JDBCTests.java
Normal file
36
VamPa_MySQL/src/test/java/com/vam/persistence/JDBCTests.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package com.vam.persistence;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class JDBCTests {
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnection() {
|
||||
|
||||
try(Connection con =
|
||||
DriverManager.getConnection(
|
||||
"jdbc:mysql://localhost:3306/ksj?serverTimezone=Asia/Seoul",
|
||||
"root",
|
||||
"1234")){
|
||||
System.out.println(con);
|
||||
} catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
#Generated by Maven Integration for Eclipse
|
||||
#Sat Aug 08 00:10:19 KST 2020
|
||||
#Sat Aug 08 00:16:25 KST 2020
|
||||
version=1.0.0-BUILD-SNAPSHOT
|
||||
groupId=com.vam
|
||||
m2e.projectName=VamPa_MySQL
|
||||
|
||||
@@ -117,6 +117,14 @@
|
||||
<version>8.0.18</version>
|
||||
</dependency>
|
||||
|
||||
<!-- HikariCP Connection pool -->
|
||||
<!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP -->
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>3.4.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- @Inject -->
|
||||
<dependency>
|
||||
<groupId>javax.inject</groupId>
|
||||
|
||||
Reference in New Issue
Block a user