您好,登錄后才能下訂單哦!
這期內容當中小編將會給大家帶來有關如何在SpringBoot項目中使用Oracle11g數據庫,文章內容豐富且以專業的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
1:下載ojdbc6.jar ,隨便放個英文目錄位置就好
2:命令行下輸入下行,注意最后-Dfile 為自己的下載目錄
mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.1.0 -Dpackaging=jar -Dfile=H:\eclpise-workspace\ojdbc6.jar
3:在項目的pom文件中引入下面依賴
<dependency> <groupId>com.oracle</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
完成!
驅動 | 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>com.oracle.database.jdbc</groupId> <artifactId>ojdbc6</artifactId> <version>11.2.0.4</version> </dependency>
<!--org.jumpmind.db.platform.JdbcDatabasePlatformFactory--> Constructor<? extends IDatabasePlatform> construtor = clazz.getConstructor(DataSource.class, SqlTemplateSettings.class); IDatabasePlatform platform = construtor.newInstance(dataSource, settings);
2020-10-13 16:57:47.929 INFO 13740 --- [manager-startup] o.j.metl.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] o.j.metl.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=http://localhost:9999/open/api/ml/comp/handler?name=rdbmsreader¶m=%7B%22sql%22:%22select+AIRDATA,AIRTIME+from+MAI_DATA%22,%22resourceId%22:%22abc9cfbe-44cf-4e83-9eb1-325422db9dd8%22,%22projectVersionId%22:%22f55241fd-9564-4f6a-bd0d-95a50a729000%22%7D 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.platform.JdbcDatabasePlatformFactory.createNewPlatformInstance(JdbcDatabasePlatformFactory.java:166) at org.jumpmind.metl.ui.views.design.RdbmsHandler.sqlExecute(RdbmsHandler.java:68) at org.jumpmind.metl.ui.views.design.RdbmsHandler.execute(RdbmsHandler.java:42) at org.jumpmind.metl.core.handler.HandlerService.execute(HandlerService.java:14) 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.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.$Proxy138.execute(Unknown Source) at com.yak.api.mlengine.CompController.handler(CompController.java:53) 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.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:870) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:776) at org.springframework.web.servlet.mvc.method.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.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:158) at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:126) at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:111) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at com.yak.platform.api.config.CORSFilter.doFilter(CORSFilter.java:71) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:84) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.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.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.jumpmind.db.platform.JdbcDatabasePlatformFactory.createNewPlatformInstance(JdbcDatabasePlatformFactory.java:160) ... 71 more Caused by: java.lang.NoClassDefFoundError: org/springframework/jdbc/support/lob/OracleLobHandler at org.jumpmind.db.platform.oracle.OracleLobHandler.<init>(OracleLobHandler.java:16) at org.jumpmind.db.platform.oracle.OracleDatabasePlatform.createSqlTemplate(OracleDatabasePlatform.java:70) at org.jumpmind.db.platform.oracle.OracleDatabasePlatform.createSqlTemplate(OracleDatabasePlatform.java:34) at org.jumpmind.db.platform.AbstractJdbcDatabasePlatform.<init>(AbstractJdbcDatabasePlatform.java:47) at org.jumpmind.db.platform.oracle.OracleDatabasePlatform.<init>(OracleDatabasePlatform.java:55) ... 76 more Caused by: java.lang.ClassNotFoundException: org.springframework.jdbc.support.lob.OracleLobHandler at java.net.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>
上述就是小編為大家分享的如何在SpringBoot項目中使用Oracle11g數據庫了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。