SpringMVC框架下,Oracle数据源在spring-servlet.xml中的配置如下:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<property name="url">
<value>oracle:thin:@127.0.0.1:1521:orcl</value>
</property>
<property name="username">
<value>scott</value>
</property>
<property name="password">
<value>XXXXX</value>
</property>
</bean>
异常如下:
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'oracle.jdbc.driver.OracleDriver' for connect URL 'oracle:thin:@127.0.0.1:1521:orcl'
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:573)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:637)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:666)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:674)
at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:734)
at com.springdemo.module.usermgr.dao.UserMgrDao.getUserByColunm(UserMgrDao.java:24)
at com.springdemo.module.usermgr.service.UserMgrService.getUserByUserName(UserMgrService.java:44)
... 30 more
错误原因:url配置不正确,应该为jdbc:oracle:thin:@127.0.0.1:1521:orcl