1

I'm struggling with establishing connection to my database using JDBC. I've done already all necessary things mentioned in documentation.

  1. I've got database working on my laptop - Oracle XE 11g rel. 2 with SID="xe", checked with SQL Developer
  2. I have proper driver - ojdbc6.jar - and added it to my project in Eclipse's Java Build Path properties
  3. I wrote few basic lines with try/catch block to establish connection:

        Connection myConn = DriverManager.getConnection("jdbc:oracle:thin@localhost:1521:xe",
                "system", "somepass");
    
        Statement myStat = myConn.createStatement();
    
        ResultSet myRe = myStat.executeQuery("SELECT * from PATIENTS");
    
        while(myRe.next()){
            System.out.println(myRe.getString("LAST_NAME"));
        }
    
        myConn.close();
        myRe.close();
    

But after running my code i receive error "Invalid Oracle URL specified". Everything looks fine but I am just starting with JDBC.. Did I miss something?

1 Answer 1

8

You are missing a colon - use

jdbc:oracle:thin:@localhost:1521:xe
                ^

instead of

jdbc:oracle:thin@localhost:1521:xe
               ^^^

as the connection string.

See also https://docs.oracle.com/cd/E11882_01/appdev.112/e13995/oracle/jdbc/OracleDriver.html

... Where the URL is of the form:

jdbc:oracle:<drivertype>:@<database>
Sign up to request clarification or add additional context in comments.

3 Comments

What a shame.. Thank You so much! Well, it appears that 2:00 AM is not the best time for coding :) Cheers!
No issue - we probably all had and still have those experiences :-)
@Andreas Fester please see my question stackoverflow.com/q/45284753/6303688

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.