Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error connecting to Oracle DB from Java

Tags:

oracle

jdbc

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)
like image 732
Winz Avatar asked Nov 12 '11 11:11

Winz


People also ask

How can I get DB connection exception in java?

getConnection(url, username,password); } catch (ClassNotFoundException e) { System. out. println("NO JDBC driver"); return null; } catch(IOException e) { System.

How do I handle sql SQLException in java?

SQLException MethodsGets the JDBC driver's error message for an error, handled by the driver or gets the Oracle error number and message for a database error. Gets the XOPEN SQLstate string. For a JDBC driver error, no useful information is returned from this method.

What is JDBC connection error?

JDBC connection errors. Connection errors are typically caused by incorrect or invalid connection string parameters, such as an invalid host name or database name. Verify that you are using correct and valid connection string parameters for the Gate.


2 Answers

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 /

like image 71
uwe Avatar answered Sep 23 '22 03:09

uwe


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;.

like image 20
Luke Woodward Avatar answered Sep 22 '22 03:09

Luke Woodward