1

After searching allot I'm still unable to connect java with oracle I used the following program.

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
public class LoadDriver{
    public static void main(String[] args){
        try{
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection con = DriverManager.getConnection("jdbc:oracle:thin:scott/scott@localhost:1521:pdborcl");
        }catch(SQLException e){
            System.out.println(e.getMessage());
        }catch(ClassNotFoundException e){
            System.out.println("Class Not Found");
        }
    }
}

I'm getting error.

Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
localhost:1521:pdborcl

Because getConnection throwing SQLException I tried all ways like jdbc:oracle:thin:@localhost:1521:pdborcl,scott,pass but still unable to connect. Can any one help to connect?

  • 1
    Why aren't you showing the actual error with `e.getMessage()`, instead of just substituting your own unhelpful message? Find the actual error from Oracle. I suspect you need to supply the service name rather than the SID but that's just a guess. – Alex Poole Apr 08 '16 at 17:23
  • Good Point. `Listener refused the connection with the following error: ORA-12505, TNS:listener does not currently know of SID given in connect descriptor The Connection descriptor used by the client was: localhost:1521:pdborcl` I'm getting this message. –  Apr 08 '16 at 17:25
  • OK, does using the service name instead work: j`dbc:oracle:thin:scott/scott@localhost:1521/pdborcl` i.e. replacing the last colon with a slash? If not is the database (and service, if you're on Windows) running? – Alex Poole Apr 08 '16 at 17:26
  • @AlexPoole `ORA-28040: No matching authentication protocol` now this error.` now this error. –  Apr 08 '16 at 17:29
  • [This](http://stackoverflow.com/q/24100117/266304) then? – Alex Poole Apr 08 '16 at 17:30
  • @AlexPoole I already using ojdbc14.jar ` should I use ` ojdbc6.jar ` ? –  Apr 08 '16 at 17:32
  • Seems so; [see this too](http://stackoverflow.com/q/31141392/266304). If that works I'll close this as a duplicate. – Alex Poole Apr 08 '16 at 17:33
  • @AlexPoole how I can test if connection made sucussfully? –  Apr 08 '16 at 17:35
  • 1
    Not sure what you mean. If you didn't get an error then it was successful. But having made a connection you presumably want to run a query or do some other work; a successful query would certainly give you confidence... – Alex Poole Apr 08 '16 at 17:38
  • There is no clear answer for this problem except to try different things - How did you connect it to this Oracle instance outside of JDBC? SQLPLUS? Also will you be able to telnet to the port? Are you using any sort of virtualbox to run Oracle in localhost? – Baski Apr 09 '16 at 03:53

0 Answers0