Skip to content
Advertisement

Unable to establish JDBC connection to Oracle DBMS in Eclipse

I’m using Oracle 18c Express edition and trying to connect to the same using the below code.

DriverManager.getConnection("jdbc:oracle:thin://@localhost:1521/XE", "system", "Root123");

And upon execution, there’s an exception:

java.sql.SQLException: Invalid Oracle URL specified

I am unable to figure out what’s wrong with the URL. Kindly help resolve this issue. TIA.

Advertisement

Answer

According to Oracle’s documentation the URL should be:

jdbc:oracle:<drivertype>:<user>/<password>@<database>

Where user and password can be provided as connection properties:

Connection conn = DriverManager.getConnection
  ("jdbc:oracle:thin:@myhost:1521:orcl", "scott", "tiger");

You probably need to remove the // from the URL as well:

jdbc:oracle:thin:@localhost:1521:XE
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement