I want to connect Oracle DB.
My .ora :
AUTACSRV120000, AUTACSRV120000.world =
(DESCRIPTION =
(ADDRESS_LIST =
(FAILOVER = ON)
(LOAD_BALANCE = OFF)
(ADDRESS = (PROTOCOL = TCP)(HOST = infra-dbaas01.noe.rct.fr)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = infra-dbaas02.pcy.rct.fr)(PORT = 1521))
)
(LOAD_BALANCE = YES)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = AUTAC_fes.dbaas.rct.fr)
)
When i want to connect i use
jdbc:oracle:thin:@AUTACSRV120000, AUTACSRV120000.world
result :
Exception in thread "main" java.sql.SQLRecoverableException: Erreur d'E/S: Inval
id connection string format, a valid format is: "host:port:sid"
But if i edit .ora to
AUTACSRV120000 =
(DESCRIPTION =
(ADDRESS_LIST =
(FAILOVER = ON)
(LOAD_BALANCE = OFF)
(ADDRESS = (PROTOCOL = TCP)(HOST = infra-dbaas01.noe.rct.fr)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = infra-dbaas02.pcy.rct.fr)(PORT = 1521))
)
(LOAD_BALANCE = YES)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = AUTAC_fes.dbaas.rct.fr)
)
and use
jdbc:oracle:thin:@AUTACSRV120000
The connection is OK
I do not have the right to leave the file edit.
Possibly two options: 1) use the service name to connect similar to here ( Java JDBC - How to connect to Oracle using Service Name instead of SID ) but I was able to test this only by using one host. so in your example: DB URL will be: jdbc:oracle:thin:@//infra-dbaas01.noe.rct.fr:1522/AUTAC_fes.dbaas.rct.fr
2) we can use the TNS entry as is in the connection description as mentioned here: https://docs.oracle.com/cd/B28359_01/java.111/b31224/jdbcthin.htm
String connString = "jdbc:oracle:thin:@(description=(address_list=
(address=(protocol=tcp)(port=1521)(host=prodHost)))
(connect_data=(INSTANCE_NAME=ORCL)))";
OracleDataSource ods = new OracleDataSource();
ods.setURL(connString);
ods.setUser("scott");
ods.setPassword("tiger");
Connection conn = ods.getConnection();
JDBC Thin connection supports only one TNS alias. So, you cannot provide "jdbc:oracle:thin:@AUTACSRV120000, AUTACSRV120000.world". You should try with only one TNS alias name.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.