如何在SpringBoot项⽬中使⽤Oracle11g数据库
在SpringBoot项⽬中使⽤Oracle11g数据库
具体步骤如下:
1:下载ojdbc6.jar ,随便放个英⽂⽬录位置就好
2:命令⾏下输⼊下⾏,注意最后-Dfile 为⾃⼰的下载⽬录
mvn install:install-file -acle -DartifactId=ojdbc6 -Dversion=11.2.0.1.0 -Dpackaging=jar -Dfile=H:\eclpise-workspace\ojdbc6.jar
3:在项⽬的pom⽂件中引⼊下⾯依赖
<dependency>
<groupId&acle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.1.0</version>
</dependency>
4:在项⽬的配置⽂件中写数据库的连接信息,其中,假设Oracle连接ip为127.0.0.1,端⼝号为1521,数据库为database,⽤户名为username,密码为password
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@127.0.0.1:1521:database
spring.datasource.username=username
spring.datasource.password=password
完成!
SpringBoot 2.0连接Oracle 11g遇到的问题
基本配置信息:
驱动oracle.jdbc.driver.OracleDriver
连接Url jdbc:oracle:thin:@192.168.112.129:1521:orcl
⽤户System
密码Aa123456
添加驱动包:
这⾥添加的是ojdbc6包,因为之前在Davinci系统使⽤ojdbc14时报错了,我使⽤的Jdk1.8的版本。
ojdbc6.jar⽐ojdbc14.jar的版本⾼得多,因为⾥⾯的6是指⽀持jdk1.6 ,⽽14是指⽀持jdk1.4。
<dependency>
<groupId&acle.database.jdbc</groupId>
jdk怎么使用
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4</version>
</dependency>
创建IDatabasePlatform时出现报错
<!--org.jumpmind.db.platform.JdbcDatabasePlatformFactory-->
Constructor<? extends IDatabasePlatform> construtor = Constructor(DataSource.class, SqlTemplateSettings.class);
IDatabasePlatform platform = wInstance(dataSource, settings);
2020-10-13 16:57:47.929  INFO 13740 --- [manager-startup] l.core.runtime.AgentRuntime      : Deploying the 本地数据库 resource to the <default user on DESKTOP-INGH9R2> agent
resourceId:abc9cfbe-44cf-4e83-9eb1-325422db9dd8
sql:select AIRDATA,AIRTIME from MAI_DATA
projectVersionId:f55241fd-9564-4f6a-bd0d-95a50a729000
2020-10-13 16:57:49.150  INFO 13740 --- [manager-startup] l.core.runtime.AgentRuntime      : Deploying the Oracle数据源 resource to the <default user on DESKTOP-INGH9R2> agent
2020-10-13 16:57:49.308  INFO 13740 --- [nio-9999-exec-1] o.j.d.p.JdbcDatabasePlatformFactory      : Detected database 'Oracle', version '11', protocol 'oracle'
2020-10-13 16:57:49,342 ERROR [GlobalExceptionHandler.java:47] : requestUrl=localhost:9999/open/api/ml/comp/handler?name=rdbmsreader¶m=%7B%22sql%22:%22select+AIRDATA,AIRTIME+from+MAI_DATA%22,%22resourceId%22:%22abc9 2020-10-13 16:57:49,343 ERROR [GlobalExceptionHandler.java:27] : System_error:requestId=1516430392
org.jumpmind.db.platform.DdlException: Could not create a platform of type Oracle
at org.jumpmind.db.ateNewPlatformInstance(JdbcDatabasePlatformFactory.java:166)
at l.ui.views.design.RdbmsHandler.sqlExecute(RdbmsHandler.java:68)
at l.ui.views.ute(RdbmsHandler.java:42)
at l.core.ute(HandlerService.java:14)
flect.NativeMethodAccessorImpl.invoke0(Native Method)
flect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
flect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at flect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:338)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:197)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:136)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$ute(Unknown Source)
at com.yak.api.mlengine.CompController.handler(CompController.java:53)
flect.NativeMethodAccessorImpl.invoke0(Native Method)
flect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
flect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at flect.Method.invoke(Method.java:498)
at org.hod.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209)
at org.hod.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
at org.springframework.web.hod.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
at org.springframework.web.hod.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:870)
at org.springframework.web.hod.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:776)
at org.springframework.web.hod.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:870)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at at.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.ics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:158)
at org.springframework.ics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:126)
at org.springframework.ics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebM
vcMetricsFilter.java:111)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.yak.fig.CORSFilter.doFilter(CORSFilter.java:71)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.boot.ace.servlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:84)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496)
at org.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.tor.CoyoteAdapter.service(CoyoteAdapter.java:342)
at http11.Http11Processor.service(Http11Processor.java:803)
at AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
at at.util.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
at at.util.SocketProcessorBase.run(SocketProcessorBase.java:49)
at urrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at urrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at at.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: flect.InvocationTargetException
wInstance0(Native Method)
wInstance(NativeConstructorAccessorImpl.java:62)
wInstance(DelegatingConstructorAccessorImpl.java:45)
at wInstance(Constructor.java:423)
at org.jumpmind.db.ateNewPlatformInstance(JdbcDatabasePlatformFactory.java:160)
... 71 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/jdbc/support/lob/OracleLobHandler
at org.jumpmind.acle.OracleLobHandler.<init>(OracleLobHandler.java:16)
at org.jumpmind.ateSqlTemplate(OracleDatabasePlatform.java:70)
at org.jumpmind.ateSqlTemplate(OracleDatabasePlatform.java:34)
at org.jumpmind.db.platform.AbstractJdbcDatabasePlatform.<init>(AbstractJdbcDatabasePlatform.java:47)
at org.jumpmind.acle.OracleDatabasePlatform.<init>(OracleDatabasePlatform.java:55)
... 76 more
Caused by: java.lang.ClassNotFoundException: org.springframework.jdbc.support.lob.OracleLobHandler
at java.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
.
.. 81 more
解决⽅案:
经查询,在初始化OracleJdbcSqlTemplate时,由于SpringBoot2.0中使⽤的是Spring-jdbc-5.0.4,出现了上⾯的报错信息。该代码之前使⽤spring4的spring-jdbc.jar就不会报错,因为spring 5之后就不存在OracleLobHandler这个类了。
由于不想修改代码,继续沿⽤⽼版本:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.2.6.RELEASE</version>
</dependency>
以上为个⼈经验,希望能给⼤家⼀个参考,也希望⼤家多多⽀持。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。