0

i get the error while connecting my jdbc program to the oracle from last 3 days i tries to solve this problem using the online solution which i got from the google but it cant solve my problem this is my code for sqlplus connection

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Main{
   public static void main(String args[]){
      try{
        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection con=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:ex","system","12345");
        System.out.println(con.toString());
    }catch(Exception e){
        if(e instanceof SQLException){
            e.printStackTrace();
        }
           System.out.println(e.toString());
   }
  }
}

error that i got while compile the from with the command prompt and my listener.ora file is look like this

my oracle version is Version 11.2.0.2.0

my jdbc driver version is ojdbc6-11.2.0.2.0this is the status of mylistener which i got with<code>>lsnrctl stat</code>

error while compile the java program

my listener.ora file look like this

this is my listener.log file while i compile the program with the command prompt

Wed Jan 27 08:40:20 2016
27-JAN-2016 08:40:20 * (CONNECT_DATA=(SID=ex)(CID=(PROGRAM=JDBC Thin Client)(HOST=__jdbc__)(USER=Jagdish))) * (ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=52366)) * establish * ex * 12505
TNS-12505: TNS:listener does not currently know of SID given in connect descriptor
Wed Jan 27 08:40:32 2016
27-JAN-2016 08:40:32 * service_update * xe * 0
Wed Jan 27 08:41:34 2016
27-JAN-2016 08:41:34 * service_update * CLRExtProc * 0
27-JAN-2016 08:41:36 * service_update * xe * 0
Wed Jan 27 08:43:23 2016
27-JAN-2016 08:43:23 * service_update * CLRExtProc * 0
Wed Jan 27 08:45:11 2016
27-JAN-2016 08:45:11 * service_update * CLRExtProc * 0
Wed Jan 27 08:46:57 2016
27-JAN-2016 08:46:57 * service_update * CLRExtProc * 0
Wed Jan 27 08:48:44 2016
27-JAN-2016 08:48:44 * service_update * CLRExtProc * 0
Wed Jan 27 08:50:30 2016
27-JAN-2016 08:50:30 * service_update * xe * 0
27-JAN-2016 08:50:31 * service_update * CLRExtProc * 0
Wed Jan 27 08:51:30 2016
27-JAN-2016 08:51:30 * service_update * xe * 0
27-JAN-2016 08:51:36 * service_update * xe * 0
Wed Jan 27 08:52:18 2016
27-JAN-2016 08:52:18 * service_update * CLRExtProc * 0
Wed Jan 27 08:54:05 2016
27-JAN-2016 08:54:05 * service_update * CLRExtProc * 0
Wed Jan 27 08:55:01 2016
27-JAN-2016 08:55:01 * service_update * xe * 0
Wed Jan 27 08:55:31 2016
27-JAN-2016 08:55:31 * service_update * xe * 0
Wed Jan 27 08:55:52 2016
27-JAN-2016 08:55:52 * service_update * CLRExtProc * 0
Wed Jan 27 08:57:41 2016
27-JAN-2016 08:57:41 * service_update * CLRExtProc * 0
Wed Jan 27 08:59:28 2016
27-JAN-2016 08:59:28 * service_update * CLRExtProc * 0
Wed Jan 27 09:01:16 2016
27-JAN-2016 09:01:16 * service_update * CLRExtProc * 0
Wed Jan 27 09:01:37 2016
27-JAN-2016 09:01:37 * service_update * xe * 0
Wed Jan 27 09:03:03 2016
27-JAN-2016 09:03:03 * service_update * CLRExtProc * 0
Wed Jan 27 09:03:27 2016
27-JAN-2016 09:03:27 * (CONNECT_DATA=(SID=ex)(CID=(PROGRAM=JDBC Thin Client)(HOST=__jdbc__)(USER=Jagdish))) * (ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=52658)) * establish * ex * 12505
TNS-12505: TNS:listener does not currently know of SID given in connect descriptor

and i tried to solve this error usin the following link which i found while googler

solution which is from the stackoverflow

coderech solution

another solution which i got from the stackoverflow

but finally all and all my work i cant able to resolve this problem please if anyone know the soltion the please give the solution it's to usefull for me please and thanks in advance.....hope to get answer

Community
  • 1
  • 1
Jagdish
  • 129
  • 1
  • 8

1 Answers1

0

You have your instance/SID the wrong way around (ex). It should read:

Connection con=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:XE","system","12345");
Rob Mascaro
  • 791
  • 7
  • 16
  • sorry sir its not working for me i already have tried for that and after your answer i am try it again but its not solving my problem i have windows 10 installed on the computer is there any problem with it? – Jagdish Jan 27 '16 at 16:19
  • try Connection con=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:xe","system","12345"); or Connection con=DriverManager.getConnection("jdbc:oracle:thin:system/12345@127.0.0.1:1521:xe"); – Rob Mascaro Jan 27 '16 at 23:48
  • Recommendation is to use the long form connection URL jdbc:oracle:thin:@(DESCRIPTION= (ADDRESS=(PROTOCOL=tcp)(HOST=myhost)(PORT=1521)) (CONNECT_DATA=(SERVICE_NAME=myorcldbservicename))) Easy Connect URL: jdbc:oracle:thin:@//localhost:1521/myorcldbservicename – Nirmala Jan 28 '16 at 18:46