java - Error creating bean ... could not load JDBC driver class [oracle.jdbc.driver.OracleDriver] -
i have written code run query using jdbc on spring exception (see below)
here's context.xml
<bean id="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource"> <property name="driverclassname" value="oracle.jdbc.driver.oracledriver"/> <property name="url" value="jdbc:oracle:thin:@mohsen-pc:1521:mydb"/> <property name="username" value="system"/> <property name="password" value="123"/> </bean> <bean id="lobhandler" class="org.springframework.jdbc.support.lob.oraclelobhandler"> <property name="nativejdbcextractor" ref="nativejdbcextractor"/> </bean> <bean id="nativejdbcextractor" class="org.springframework.jdbc.support.nativejdbc.commonsdbcpnativejdbcextractor"/> <bean id="jdbctemplate" class="org.springframework.jdbc.core.jdbctemplate"> <property name="datasource" ref="datasource"/> </bean> </beans>
main.java
import javax.sql.datasource; import org.springframework.context.applicationcontext; import org.springframework.context.support.classpathxmlapplicationcontext; import org.springframework.jdbc.core.jdbctemplate; class main { public static void main(string args[]) throws exception { applicationcontext ac = new classpathxmlapplicationcontext("context.xml"); datasource datasource = (datasource) ac.getbean("datasource"); jdbctemplate jdbctemplate = new jdbctemplate(datasource); system.out.println(jdbctemplate.queryforlist("select employee_id employee", long.class)); } }
the exception see is:
exception in thread "main" org.springframework.beans.factory.beancreationexception: error creating bean name 'datasource' defined in class path resource [context.xml]: error setting property values; nested exception org.springframework.beans.propertybatchupdateexception; nested propertyaccessexceptions (1) are: propertyaccessexception 1: org.springframework.beans.methodinvocationexception: property 'driverclassname' threw exception; nested exception java.lang.illegalstateexception: not load jdbc driver class [oracle.jdbc.driver.oracledriver] @ org.springframework.beans.factory.support. abstractautowirecapablebeanfactory.applypropertyvalues( abstractautowirecapablebeanfactory.java:1396)
edit: cut remainder of stack trace above exception sufficient illuminate problem.
what going wrong here?
looks missing oracle jdbc driver in classpath. please download jar file this path , add classpath.
edited
spring jdbc template layer works on top of raw jdbc layer. provides utility methods make database access easier. layer internally needs jdbc layer work every database want connect database's driver has included, in case need include oracle driver.
Comments
Post a Comment