๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Study

[Java] M1 Oracle Cloud DB + Java ์—ฐ๊ฒฐํ•˜๊ธฐ

by JulesJ 2021. 10. 2.
728x90
Mac m1 ์œ ์ €์ž…๋‹ˆ๋‹ค. ๋ณด์‹ค ๋•Œ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”!

 

๋ฐฐ์šฐ๊ณ  ์žˆ๋Š” ๊ฐ•์˜์—์„œ๋Š” window ๊ธฐ๋ฐ˜์ด๋ผ local๋กœ oracle DB๋ฅผ ์ด์šฉํ•˜๋Š” ๋ฐ, ์ €๋งŒ m1 ์ด๋”๋ผ๊ตฌ์š”..

๋งค๋ฒˆ ์ฐพ์•„์„œ ํ•˜๊ธฐ ํž˜๋“ค์—ˆ์–ด์„œ ์ œ๊ฐ€ ์•Œ๊ฒŒ ๋œ ์ •๋ณด๋ผ๋„ ๊ธฐ๋กํ•˜๊ณ  ๊ณต์œ ํ•ฉ๋‹ˆ๋‹ค..!

 

> ๊ฐœ๋ฐœ ํ™˜๊ฒฝ

Java -> Eclipse , SpringToolSuite4 ์ด์šฉ

Oracle Cloud -> ์ž์œจ์šด์˜ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ด์šฉ

DBeaver๋กœ DB ๊ด€๋ฆฌ

 

> Java ์„ค์ •ํ•˜๊ธฐ

Java์— db connection ํ•  ๋•Œ local๋กœ DB ์—ฐ๊ฒฐ

 

- MySQL

public class Constant {
  public static final String DRIVER = "com.mysql.cj.jdbc.Driver";
  public static final String URL = "jdbc:mysql://127.0.0.1:3306/javadb?useUnicode=true&characterEncoding=utf8";
  public static final String USER = "admin";
  public static final String PASSWORD = "1234";
}

 

- Oracle DB

public class Constant {
  public static final String DRIVER = "oracle.jdbc.driver.OracleDriver";
  public static final String URL = "jdbc:oracle:thin:@localhost:1521:XE";
  public static final String USER = "admin";
  public static final String PASSWORD = "1234";
}

์ด๋Ÿฐ ์‹์œผ๋กœ Constant class๋ฅผ ๋งŒ๋“ค๊ณ 

Open class๋„ ๋”ฐ๋กœ ๋งŒ๋“ค์–ด ์ด์šฉํ•˜๋˜ ์ค‘์ด์—ˆ์Šต๋‹ˆ๋‹ค.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Open {
  private static Connection con;

  public static Connection getConnection() {

    try {
      Class.forName(Constant.DRIVER);

      con = DriverManager.getConnection(Constant.URL, Constant.USER, Constant.PASSWORD);
   
      
    } catch (ClassNotFoundException | SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return con;
  }
}

 

- Oracle Cloud DB ์—ฐ๊ฒฐ

๋จผ์ € driver, url์€ ์•„๋ž˜์™€ ๊ฐ™์ด, ์œ ์ €์ด๋ฆ„๊ณผ ๋น„๋ฒˆ์€ ์„ค์ •ํ•˜์‹ ๋Œ€๋กœ(ํ˜น์€ ์„ค์ •๋œ username ์ด์šฉํ•˜์…”์„œ) ์ž…๋ ฅํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

public class Constant {
	public static final String DRIVER = "oracle.jdbc.pool.OracleDataSource";
	public static final String URL = "jdbc:oracle:thin:@db์ด๋ฆ„_high?TNS_ADMIN=์ „์ž์ง€๊ฐ‘๊ฒฝ๋กœ";
	public static final String USER = "admin";
	public static final String PASSWORD = "Oracle_Colud_DB_๋น„๋ฒˆ";
}

์œ„ ์ฝ”๋“œ์™€ ๊ฐ™์ด ์„ค์ •ํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค..!

 

์ด ์ฝ”๋“œ๋งŒ ์„ค์ •ํ•˜๋ฉด, ๋ฐ”๋กœ ์—ฐ๊ฒฐ ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค!

 

 

> Oracle ์—์„œ ํ•„์š”ํ•œ jar ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ

Oracle ์ง€์› ์„ผํ„ฐ - Cloud / Cloud platform / Autonomous Database

Using Oracle Autonomous Database on Shared Exadata Infrastructure ๋ฌธ์„œ์˜

์ง€๊ฐ‘์„ ์‚ฌ์šฉํ•œ JDBC ์”ฌ ์—ฐ๊ฒฐ(mTLS)์— ํ•ด๋‹น ๋‚ด์šฉ์— ๋Œ€ํ•œ ์„ค๋ช…์ด ์žˆ์Šต๋‹ˆ๋‹ค.

์—ฌ๊ธฐ ์‚ฌ์ง„์—์„œ 4๋ฒˆ์„ ๋ณด๋ฉด jar๋ฅผ ์ถ”๊ฐ€ํ•˜๋ผ๋Š” ์„ค๋ช…์ด ์žˆ์Šต๋‹ˆ๋‹ค.

 

์˜ค๋ผํด ๋“ค์–ด๊ฐ€์„œ ํ•„์š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ojdbc8, ucp, oraclepki, osdt_cert, osdt_core ๋“ฑ์˜ jar ํŒŒ์ผ์„ ๋‹ค์šด ๋ฐ›์Šต๋‹ˆ๋‹ค.

 

์—ฐ๊ฒฐ ๋! 

sts javaํŒŒ์ผ์—์„œ DB ์—ฐ๊ฒฐ์ด ์ž˜ ๋ฉ๋‹ˆ๋‹ค..!

 

 

 

์ถœ์ฒ˜ : [Oracle ๋ฌธ์„œ](https://docs.oracle.com/en/cloud/paas/autonomous-database/adbsa/connect-jdbc-thin-wallet.html#GUID-1640CC02-BF3E-48C2-8FFE-A596614A6A40)

 

Using Oracle Autonomous Database on Shared Exadata Infrastructure

Autonomous Database mandates a secure connection that uses Transport Layer Security (TLSv1.2). Depending on the configuration options, Autonomous Database supports mTLS and TLS authentication. This section covers using JDBC Thin Connections with a wallet (

docs.oracle.com

[db JDBC Driver ๋‹ค์šด๋กœ๋“œ ํŽ˜์ด์ง€](https://www.oracle.com/database/technologies/appdev/jdbc-ucp-183-downloads.html)

 

 

 

Fin.๐Ÿง

๋Œ“๊ธ€