6

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

The connection call is:

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

I receive 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)

5 Answers 5

6

in a similar case for me worked a slightly other connect string: jdbc:oracle:thin:@winson.net:1522:hcrod

really without the // and with : instead of /

Sign up to request clarification or add additional context in comments.

Comments

1

I've seen this error come up a few times when I've started the TNS listener after I started the database. When the database starts up it registers itself with the listener if the listener is running, but if the listener isn't running it can't do this.

It's possible to manually persuade the database to register itself with the listener. To do this, connect to the database as SYS and run the SQL statement ALTER SYSTEM REGISTER;.

1 Comment

I've given the only command you need. Log in as sys - I know you can do this as you've commented on this answer - and run the one command I've mentioned.
0

It sounds like the port on the server isn't listening, port 1522.

Can you telnet the port successfully?

1 Comment

The connection host 'winson.net:1522/hcrod' is correct as I could connect to it successfully thru' SQL devloper.
0

Oracle's JDBC thin URI syntax is as follows:

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

So:

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

Note the two slashes added after the @ symbol.

Comments

0

i think port number for oracle is 1521

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.