Java 将错误获取为";SQL状态:08001未找到适合jdbc的驱动程序:oracle:thin:@128:23:44:01:12345:pppp\u rr

Java 将错误获取为";SQL状态:08001未找到适合jdbc的驱动程序:oracle:thin:@128:23:44:01:12345:pppp\u rr,java,jdbc,Java,Jdbc,有人能指出我在这里做错了什么吗: 获取错误消息为“SQL状态:08001” 找不到适合jdbc的驱动程序:oracle:thin:@128:23:44:01:12345:pppp\u rr选择了JAVA\u工具选项:-Duser.home=C:\Users\123ert“ 我无法使用Oracle数据库对其进行准确测试,但我知道必须先注册驱动程序,然后才能建立连接。检查以下代码,基本上是您的代码加上驾驶员注册 public static void main(String args[]) throw

有人能指出我在这里做错了什么吗:

获取错误消息为“SQL状态:08001” 找不到适合jdbc的驱动程序:oracle:thin:@128:23:44:01:12345:pppp\u rr选择了JAVA\u工具选项:-Duser.home=C:\Users\123ert


我无法使用Oracle数据库对其进行准确测试,但我知道必须先注册驱动程序,然后才能建立连接。检查以下代码,基本上是您的代码加上驾驶员注册

public static void main(String args[]) throws Exception {
    // registration for the driver, it's needed, 
    // otherwise there will be "no suitable driver found"
    Class.forName("oracle.jdbc.driver.OracleDriver");

    try (Connection conn = DriverManager.getConnection(
            "jdbc:oracle:thin:@128:23:44:01:12345:pppp_rr", "Test123", "********")) {

        if (conn != null) {
            System.out.println("Connected to the database!");
        } else {
            System.out.println("Failed to make connection!");
        }

    } catch (SQLException e) {
        System.err.format("SQL State: %s\n%s", e.getSQLState(), e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

我认为您必须先注册驱动程序,然后才能使用
DriverManager
建立连接。一种可能是只调用
DriverManager.registerDriver(新的oracle.jdbc.OracleDriver())在您的
之前尝试
-block(请参阅)。@Routray不客气!有其他的方法,但如果这是可行的,那么很好!
public static void main(String args[]) throws Exception {
    // registration for the driver, it's needed, 
    // otherwise there will be "no suitable driver found"
    Class.forName("oracle.jdbc.driver.OracleDriver");

    try (Connection conn = DriverManager.getConnection(
            "jdbc:oracle:thin:@128:23:44:01:12345:pppp_rr", "Test123", "********")) {

        if (conn != null) {
            System.out.println("Connected to the database!");
        } else {
            System.out.println("Failed to make connection!");
        }

    } catch (SQLException e) {
        System.err.format("SQL State: %s\n%s", e.getSQLState(), e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
    }
}