0

I am new to spring and developing spring jdbc application. but driver class is not loaded. am getting exception that

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

and my xml file is as follows:

<bean id="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:xe" />
<property name="username" value="system" />
property name="password" value="surekha" />  
</bean>

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="ds"></property>
</bean>

<bean id="edao" class="EmployeeDao">
<property name="jdbcTemplate" ref="jdbcTemplate"></property>
</bean>


</beans>

anyone help me to this problem. thanks in advance.

Rekha S
  • 73
  • 1
  • 1
  • 11
  • Looks like oracle jadbc driver is missing.Download it from here http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html – Rohan Nov 18 '14 at 05:29
  • now am getting Exception in thread "main" org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Listener refused the connection with the following error: ORA-12505, TNS:listener does not currently know of SID given in connect descriptor – Rekha S Nov 18 '14 at 06:17
  • Are you missing `<` before `property` and `bean`.Also try changing `jdbc:oracle:thin:@localhost:1521:xe` to `jdbc:oracle:thin:@localhost:1521/xe`.Check http://stackoverflow.com/questions/5661610/tns-12505-tnslistener-does-not-currently-know-of-sid-given-in-connect-descript – Rohan Nov 18 '14 at 06:49
  • yes I changed into jdbc:oracle:thin:@localhost:1521/xe. now am getting Exception in thread "main" org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Listener refused the connection with the following error: ORA-12514, TNS:listener does not currently know of service requested in connect descriptor Caused by: java.sql.SQLException: Listener refused the connection with the following error: ORA-12514, TNS:listener does not currently know of service requested in connect descriptor – Rekha S Nov 18 '14 at 07:08
  • Make sure that your `Oracle` listener is up and running and is configures properly. – Darshan Lila Nov 18 '14 at 07:43
  • can you please tell me, how to check oracle listener is running or not – Rekha S Nov 18 '14 at 07:58
  • In our case(Spring 4, eclipse Luna, JDK 7, ojdbc6.jar), we had to add the ojdbc jar as well as spring-jdbc.jar into /WEB-INF/lib folder and it started to work – JavaTec Feb 17 '16 at 18:57

4 Answers4

6

In your pom.xml , add this dependency :

<dependency>
    <groupId>oracle</groupId>
    <artifactId>ojdbc6</artifactId>
    <version>11.2.0.3</version>
</dependency>
Patrikoko
  • 478
  • 5
  • 5
  • ojdbc6.jar is no more available in Maven, though it was till sometime last year. Now you have to separately download it from Oracle website – JavaTec Feb 17 '16 at 18:58
1

Add Following dependency in pom.xml

    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>oracle</artifactId>
        <version>10.2.0.2.0</version>
    </dependency>
0

I had the Same problem even adding the maven dependency in my pom.xml

I downloaded manualy the .jar in https://mvnrepository.com/artifact/com.oracle/ojdbc6/12.1.0.1-atlassian-hosted

and it worked for my project.

-1

Add this jdbc-oracle.jar file into your project...

jdbc-oracle.jar is available in http://www.java2s.com/Code/Jar/j/Downloadjdbcoraclejar.htm