IllegalStateException:无法加载jdbc驱动程序

时间:2018-04-03 12:49:51

标签: java spring jdbc

我收到与exception is java.lang.IllegalStateException: Could not load JDBC driver class相同的错误。我在src / main / resources / lib中添加了ojdbc14.jar。仍然得到: -

    PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]
    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ds' defined in class path resource [dbOperations.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
    PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]

我正在加载jdbc驱动程序: -

    context = new ClassPathXmlApplicationContext("dbOperations.xml");

1 个答案:

答案 0 :(得分:4)

将jar放入src / resources / lib并不会将类文件放在类路径上。

根据您是否使用Maven或Gradle这样的内容,您需要将ojdbc jar作为依赖项添加到您的pom或gradle文件中。

如果您没有使用它,那么在启动JVM时,您必须确保在-classpath参数中列出了ojdbc jar文件。