Oracle JDBC 連線
司機:
( 注意: Maven Central 中不包含驅動程式!)
驅動類初始化:
Class.forName("oracle.jdbc.driver.OracleDriver");
連線 URL
較舊的格式,帶有 SID
"jdbc:oracle:thin:@<hostname>:<port>:<SID>"
較新的格式,帶有服務名稱
"jdbc:oracle:thin:@//<hostname>:<port>/<servicename>"
Tnsnames 喜歡進入
"jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCPS)(HOST=<hostname>)(PORT=<port>))"
+"(CONNECT_DATA=(SERVICE_NAME=<servicename>)))"
用於故障轉移的 RAC 叢集連線字串
"jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(LOAD_BALANCE=OFF)(FAILOVER=ON)"
+"(ADDRESS=(PROTOCOL=TCP)(HOST=<hostname1>)(PORT=<port1>))"
+"(ADDRESS=(PROTOCOL=TCP)(HOST=<hostname2>)(PORT=<port2>)))"
+"(CONNECT_DATA=SERVICE_NAME=<servicename>)(SERVER=DEDICATED)))"
例
connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "HR", "HRPASS");