How to connect to oracle using service name in java

1.4k Views Asked by At

I need to connect to oracle db in java

Connection con = DriverManager.getConnection("jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=hostname)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=servicename)))");

I am getting below error

java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: com.mysql.cj.core.exceptions.WrongArgumentException: Malformed database URL, failed to parse the main URL sections.
1

There are 1 best solutions below

0
On

Use this format

jdbc:oracle:thin:@//HOSTNAME:PORT/SERVICE_NAME

Example:

jdbc:oracle:thin:@//10.25.18.122:1524/abcxyz