简体   繁体   English

无法使用JDBC连接到Oracle 11g - 指定了无效的oracle URL

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

I'm struggling with establishing connection to my database using JDBC. 我正在努力使用JDBC建立与数据库的连接。 I've done already all necessary things mentioned in documentation. 我已经完成了文档中提到的所有必要的事情。

  1. I've got database working on my laptop - Oracle XE 11g rel. 我的笔记本电脑上有数据库工作 - Oracle XE 11g rel。 2 with SID="xe", checked with SQL Developer 2,SID =“xe”,用SQL Developer检查
  2. I have proper driver - ojdbc6.jar - and added it to my project in Eclipse's Java Build Path properties 我有适当的驱动程序 - ojdbc6.jar - 并将其添加到Eclipse的Java Build Path属性中的项目中
  3. I wrote few basic lines with try/catch block to establish connection: 我用try / catch块写了几个基本的行来建立连接:

      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". 但在运行我的代码后,我收到错误“指定了无效的Oracle URL”。 Everything looks fine but I am just starting with JDBC.. Did I miss something? 一切都很好,但我刚刚开始使用JDBC ..我错过了什么吗?

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 另见https://docs.oracle.com/cd/E11882_01/appdev.112/e13995/oracle/jdbc/OracleDriver.html

... Where the URL is of the form: ... URL的格式如下:

 jdbc:oracle:<drivertype>:@<database> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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