【问题标题】:Unable connect to Oracle 11g using JDBC - Invalid oracle URL specified无法使用 JDBC 连接到 Oracle 11g - 指定的 oracle URL 无效
【发布时间】:2016-03-17 10:13:02
【问题描述】:

我正在努力使用 JDBC 建立与我的数据库的连接。 我已经完成了文档中提到的所有必要的事情。

  1. 我的笔记本电脑上正在运行数据库 - Oracle XE 11g rel。 2 SID="xe",使用 SQL Developer 进行检查
  2. 我有适当的驱动程序 - ojdbc6.jar - 并将其添加到我在 Eclipse 的 Java 构建路径属性中的项目中
  3. 我用 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();
    

但在运行我的代码后,我收到错误“指定的 Oracle URL 无效”。 一切看起来都很好,但我只是从 JDBC 开始。我错过了什么吗?

【问题讨论】:

    标签: java eclipse oracle jdbc oracle11g


    【解决方案1】:

    你缺少一个冒号 - 使用

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

    而不是

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

    作为连接字符串。

    另见https://docs.oracle.com/cd/E11882_01/appdev.112/e13995/oracle/jdbc/OracleDriver.html

    ... URL 的格式为:

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

    【讨论】:

    • 真可惜.. 非常感谢!好吧,看来凌晨 2:00 不是编码的最佳时间 :) 干杯!
    • 没问题 - 我们可能都有过并且仍然有这些经历 :-)
    • @Andreas Fester 请看我的问题stackoverflow.com/q/45284753/6303688
    猜你喜欢
    • 1970-01-01
    • 2015-03-12
    • 2018-09-24
    • 1970-01-01
    • 2015-02-15
    • 1970-01-01
    • 2011-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多