3

I have downloaded oracle express 11g edition and installed that.Now i want to connect it from java application. Here is my Connection code :-

Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:example", "example","password123");

But when i am trying to connect it, it showing me following exception.

java.sql.SQLException: Listener refused the connection with the following error:  
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor

at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:419)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:536)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:228)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at javaapplication3.JavaApplication3.main(JavaApplication3.java:40)

But when i am trying to connect with "xe" database then it is connected.

Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();   
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "example","password123");

I dont know why this is happening?. Please give me some reference or hint.

6
  • 3
    Listener refused the connection with the following error: where is the error? Commented Nov 1, 2012 at 11:08
  • yea Abu.. its giving when i am trying to access "example" schema...the first code Commented Nov 1, 2012 at 11:12
  • Refer Here Commented Nov 1, 2012 at 11:13
  • @user591790 I mean you have not put the error in the question.Please edit your question with the error so that people here can help you better. Commented Nov 1, 2012 at 11:14
  • 1
    have you created example database ? Commented Nov 1, 2012 at 11:24

4 Answers 4

8

I think, you are misunderstanding between database schema and database type. In Oracle, XE means Express Edition of oracle database. ORCL means Oracle Corp.

In mysql

DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "example","password123");

`test` is a database schema.

In Oracle XE

DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "example","password123");
DriverManager.getConnection("jdbc:oracle:thin:scott/tiger@myhost:1521:orcl","example", "password123");

`example`: database schema name and DB user name are the same.
Sign up to request clarification or add additional context in comments.

Comments

5

The connection URLs for Oracle are in the format:

jdbc:oracle:thin:@HOST:PORT:SID

The SID is a site identifier. In a full oracle install you could have multiple SIDs, but for Oracle Express this will always be XE.

What you are refering to as a "database" equates to a "user" in Oracle ("example" in your code above). Tables etc... are created under that user.

Comments

1

In URL pattern XE and orcl are the service id's for the Oracle. For Oracle expressed edition "xe" is used and for Oracle Enterprised edition "orcl" is used..

Comments

0

Check which instances are known to listener by executing : lsnrctl services

Check your tnsnames.ora

Check your SID parameters for typo and invalid parameters value

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.