jdbc Oracle JDBC连接

示例

司机:

  • 12c R1

  • 11克R2

注意:该驱动程序未包含在Maven Central中!)

驱动程序类初始化:

    Class.forName("oracle.jdbc.driver.OracleDriver");

连接网址

较旧的格式,带有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");