java.sql.sqlexception:指定的oracle url无效错误

1hdlvixo  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(535)

我正在尝试用jdbc驱动程序连接oracle数据库。我得到java.sql.sqlexception:指定的oracle url无效错误。请帮我解决这个问题。

package test_connection;

import java.sql.*;

public class TestConnection {
    public static void main(String[] args) {
        // TODO code application logic here

        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            System.out.println("Driver loaded successfully ");
            Connection con = DriverManager.getConnection("jdbc:oracle:thin@:localhost:1521:XE", username, password);
            System.out.println("Connection established successfully ");

            con.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

下面是错误的堆栈跟踪。

run:
Driver loaded successfully 
java.sql.SQLException: Invalid Oracle URL specified
BUILD SUCCESSFUL (total time: 0 seconds)
vc9ivgsu

vc9ivgsu1#

您可以从github获取一些样本。示例,数据源示例

相关问题