
create user book_ex identified by book_ex
default tablespace users
temporary tablespace temp;
grant connect, dba to book_ex;
오라클 비밀번호 사용가능 특수문자 : https://dexcore.tistory.com/733 참고
특정 문자 외 특수문자를 사용하려면 ""안에 넣어야 한다.
select dbms_xdb.gethttpport() from dual;
exec dbms_xdb.sethttpport(9090);
package org.zerock.persistence;
import static org.junit.Assert.fail;
import java.sql.Connection;
import java.sql.DriverManager;
import org.junit.Test;
import lombok.extern.log4j.Log4j;
@Log4j
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:orcl",
"book_ex",
"book_ex")){
log.info(con);
}catch(Exception e) {
fail(e.getMessage());
}
}
}
결과 : 
HikariCP 이용.
<!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.7.4</version>
</dependency>
root-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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">
<!-- Root Context: defines shared resources visible to all other web components -->
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="jdbcUrl" value="jdbc:oracle:thin:@localhost:1521:orcl"></property>
<property name="username" value="book_ex"></property>
<property name="password" value="book_ex"></property>
</bean>
<!-- HikariCP configuration -->
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<constructor-arg ref="hikariConfig" />
</bean>
<context:component-scan base-package="org.zerock.sample"></context:component-scan>
</beans>
DataSourceTests.java
package org.zerock.persistence;
import static org.junit.Assert.fail;
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;
import lombok.Setter;
import lombok.extern.log4j.Log4j;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/root-context.xml")
@Log4j
public class DataSourceTests {
@Setter(onMethod_ = { @Autowired })
private DataSource dataSource;
@Test
public void testConnection() {
try(Connection con = dataSource.getConnection()){
log.info(con);
}catch(Exception e) {
fail(e.getMessage());
}
}
}
결과 : 