没有为jdbc找到合适的驱动程序:oracle:thin:@localhost:1521:orcl

时间:2016-12-25 21:05:14

标签: java oracle jdbc

**我的JDK:** 1.8.0.112

**我的神谕:** 11.2.0.2表达

**我的IDE:** Intelij Idea 13

我的代码:

包装模型; import java.sql。*;

公共类PersonDA {

public static void main(String[] args)throws Exception {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection connection=DriverManager.getConnection("jdbc: oracle: thin:@localhost:1521:orcl","*****","********");
    Statement statement= connection.createStatement();
    ResultSet resultSet= statement.executeQuery("SELECT * FROM Person");

    while (  resultSet.next()){

        System.out.println(resultSet.getString("ID"));
        System.out.println(resultSet.getString("name"));

    }
    statement.close();
    connection.close();
}

}

异常: 线程“main”java.sql.SQLException中的异常:为jdbc找不到合适的驱动程序:oracle:thin:@localhost:1521:orcl

at java.sql.DriverManager.getConnection(DriverManager.java:689)

at java.sql.DriverManager.getConnection(DriverManager.java:247)

at model.PersonDA.main(PersonDA.java:8)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

2 个答案:

答案 0 :(得分:1)

更改您的网址:

"jdbc: oracle: thin:@//localhost:1521:orcl"

到此:

"jdbc:oracle:thin:@localhost:1521:orcl"

答案 1 :(得分:0)

<强>解决

由于&#39;:&#39;之间的空格错误而发生了异常。和#oracle&#39;代码中以及&#39;:&#39;和&#39;瘦&#39;。