Error connecting to Oracle DB with Java

Can someone please help me on why I got the following error while trying to connect to Oracle db from java ....

Call call:

Connection con = DriverManager.getConnection( "jdbc:oracle:thin:@winson.net:1522/hcrod", "manager", "passing"); 

I get the following error:

 java.sql.SQLException: Listener refused the connection with the following error: ORA-12514, TNS:listener does not currently know of service requested in connect descriptor at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:113) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:263) at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:389) at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:454) at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165) at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:802) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:185) at test_sample.main(test_sample.java:15) 
+6
source share
5 answers

in a similar case, a slightly different connection string worked for me: jdbc:oracle:thin:@winson.net:1522:hcrod

really without // and with: instead of /

+6
source

I saw how this error occurs several times when I started listening to TNS after I started working with the database. When the database starts, it is registered during listening if the listener is working, but if the listener is not working, he cannot do this.

You can manually convince the database to register with the listener. To do this, connect to the database as SYS and run the SQL ALTER SYSTEM REGISTER; statement ALTER SYSTEM REGISTER; .

+1
source

It looks like the port on the server is not listening, port 1522.

Can you telnet port successfully?

0
source

The syntax of the Oracle JDBC URI is as follows:

 jdbc:oracle:thin:[USER/PASSWORD]@//[HOST][:PORT]/SERVICE 

So:

 jdbc:oracle:thin:@//winson.net:1522/hcrod" 

Notice the two traits added after the @ symbol.

0
source

I think the port number for oracle is 1521

0
source

Source: https://habr.com/ru/post/901339/


All Articles