Java/Spring
[Spring legacy] Oracle DB 연결하기 (ojdbc11/jdk11)
1984
2023. 4. 22. 18:39
1. SQL Developer 설치 폴더 > jdbc > lib 폴더에 jdk 11 버전용 ojbc11.jar 파일이 존재한다.
2. 프로젝트 우클릭 > Build Path > Configure Build Path...
3. Libraries 탭 > Classpath 클릭 > Add External JARs... 클릭
3. ojdbc11.jar 선택 > Apply
4. Apply
5. 프로젝트 우클릭 > Properties > Deployment Assembly
6. Java Build Path Entries 클릭
7. ojdbc11.jar 선택 > Finish
8. Apply and Close
9. Oracle 접속 테스트 코드
package com.example.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 JDBCTest {
static {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void TestConnection() {
try (Connection conn =
DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe",
"$ID",
"$PASSWORD")) {
log.info(conn);
} catch (Exception e) {
fail(e.getMessage());
}
}
}
10. 끝
728x90