SpringMVC, Property 'driverClassName' thre

2019-08-24 13:56发布

But how come it did not get the ojdbc7.jar from lib folder that i had created in the Project root ????

I added the following

  Class.forName("oracle.jdbc.driver.OracleDriver"); 

code in the Constructor of my Controller and it threw an Exception.So i followed this link, oracle.jdbc.driver.OracleDriver ClassNotFoundException in that link i did the following,

In Eclipse,right click on your application

Run As -> Run configurations -> select your server from type filter text box

Then in Classpath under Bootstrap Entries add your classes12.jar File and Click on Apply Now, run the file.This worked for me !!....

This did work. But how come it did not get the ojdbc7.jar from lib folder ??

I have created a lib folder in my project root and kept the ojdbc7.jar in it.

But still i am getting the below error,

Property 'driverClassName' threw exception; nested exception is 
java.lang.IllegalStateException: Could not load JDBC driver class 
[oracle.jdbc.driver.OracleDriver]    

I searched the net for the same error and all say that keep the jar in the classpath. I think i have it in the classpath. But still the error persists.

I have the ojdbc7.jar. im using Oracle 12c.

Can anybody help me with it please.

In employeeServlet-servlet.xml, i have defined Datasource as,

<!-- DataSource -->
    <bean id="dataSource" 
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${database.driver}"> 
 </property>
        <property name="url" value="${database.url}"></property>
        <property name="username" value="${database.user}"></property>
        <property name="password" value="${database.password}"></property>
    </bean>   

In application.properties i have,

#Database related properties
database.driver=oracle.jdbc.driver.OracleDriver
database.url=jdbc:oracle:thin:@localhost:1521:orcl
database.user=system
database.password=oracle

In pom.xml, i have

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc7</artifactId>
    <version>${oracle.version}</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/ojdbc7.jar</systemPath> <!-- must match file name -->
</dependency>  

标签: spring-mvc
1条回答
孤傲高冷的网名
2楼-- · 2019-08-24 14:28

You got this error popping up:

Property 'driverClassName' threw exception; nested exception is 

java.lang.IllegalStateException: Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]

Test if "oracle.jdbc.driver.OracleDriver" is on your classpath like so:

try {
  Class.forName("oracle.jdbc.driver.OracleDriver");
  //on classpath
} catch(ClassNotFoundException e) {
  //not on classpath
}

If an exception occurs in Class.forName("oracle.jdbc.driver.OracleDriver");

this line causes ClassNotFoundException, because you haven't placed ojdbc14.jar file in your lib folder of the project. or You haven't set the classpath of the required jar

You might wanna read these question: Property 'driverClassName' threw exception; Could not load JDBC driver class [org.postgresql.Driver]

oracle.jdbc.driver.OracleDriver ClassNotFoundException

查看更多
登录 后发表回答