使用Druid连接oracle时报SQLException: not support oracle driver5.1

71 篇文章 0 订阅

2018-12-29 16:17:10.600 [main] ERROR c.alibaba.druid.pool.DruidDataSource 836 - {dataSourc使用Druid连接oracle时报 java.sql.SQLException: not support oracle driver 5.1

复制

2018-12-29 16:17:10.600 [main] ERROR c.alibaba.druid.pool.DruidDataSource 836 - {dataSource-1} init error
java.sql.SQLException: not support oracle driver 5.1
	at com.alibaba.druid.pool.DruidDataSource.initCheck(DruidDataSource.java:1003)
	at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:765)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1129)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1125)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:104)
	at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:625)
	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:690)
	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:722)
	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:732)
	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:782)
	at com.gb.soa.omp.ccommon.util.MyJdbcTemplate.query(MyJdbcTemplate.java:81)
	at com.gb.pay.common.dao.PosOrderDao.getOrders(PosOrderDao.java:27)
	at com.gb.pay.common.dao.PosOrderDao$$FastClassBySpringCGLIB$$2125e6a5.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
	at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
	at com.gb.pay.common.dao.PosOrderDao$$EnhancerBySpringCGLIB$$168fbefc.getOrders(<generated>)
	at com.gb.pay.common.dao.PosOrderDaoTester.getOrders(PosOrderDaoTester.java:32)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

 

今天在spring boot中配置durid去连接oracle,爆了上面的异常。

在百度 谷歌搜索不出符合我的答案后 我决定调试

报错的是这行代码:

复制

protected void initCheck() throws SQLException {
	if (JdbcUtils.ORACLE.equals(this.dbType)) {
		isOracle = true;

		if (driver.getMajorVersion() < 10) {
			throw new SQLException("not support oracle driver " + driver.getMajorVersion() + "."
								   + driver.getMinorVersion());
		}
	}
}

image.png

点进去之后:

image.png

卧槽 怎么使用mysql驱动了。

看来是配置durid的问题。

附上手工配置数据源的方法:

复制

@Bean(name="posDataSource")
@ConfigurationProperties("oracle.pos")
public DataSource posDataSource(){
	DruidDataSource datasource = new DruidDataSource();
	datasource.setUrl(posUrl);
	datasource.setUsername(posUserName);
	datasource.setPassword(posPassword);
	datasource.setDriverClassName(oracleDrivers);
	
	datasource.setInitialSize(initialSize);
	datasource.setMinIdle(minIdle);
	datasource.setMaxActive(maxActive);
	try {
		datasource.setFilters("stat,wall,log4j");
	} catch (SQLException e) {
		e.printStackTrace();
	}
	return datasource;
}

我的错误原因是在配置文件中连接oracle连接了但是驱动类选的mysql的驱动

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

#--------------------oracle   -----------------------
spring.datasource.name=dev
spring.datasource.url= jdbc:oracle:thin:@(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 11521)))(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = xe)))
spring.datasource.username=md
spring.datasource.password=md

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值