简体   繁体   中英

Unable connect to Oracle 11g using JDBC - Invalid oracle URL specified

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?

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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM