【问题标题】:Spring boot:connection oracle databasespring boot:连接oracle数据库
【发布时间】:2020-02-18 15:00:59
【问题描述】:

我正在使用带有oracle V11.2.0.4.0数据库的spring boot来开发一个微服务, 但是由于以下错误,我的 pringBootApplication 无法运行:

2020-02-18 15:24:12.943  INFO 16476 --- [           main] com.zaxxer.hikari.HikariDataSource       : 
HikariPool-1 - Starting...
2020-02-18 15:24:13.041  INFO 16476 --- [           main] com.zaxxer.hikari.pool.PoolBase          : 
HikariPool-1 - Driver does not support get/set network timeout for connections. 
(oracle.jdbc.driver.T4CConnection.getNetworkTimeout()I)
2020-02-18 15:24:13.045  INFO 16476 --- [           main] com.zaxxer.hikari.HikariDataSource       : 
HikariPool-1 - Start completed.
2020-02-18 15:24:13.058  INFO 16476 --- [           main] org.hibernate.dialect.Dialect            : 
HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
2020-02-18 15:24:13.205 **ERROR** 16476 --- [           main] o.h.e.j.e.internal.JdbcEnvironmentImpl   : 
Could not fetch the SequenceInformation from the database
2020-02-18 15:24:13.662  WARN 16476 --- [           main] o.h.engine.jdbc.spi.SqlExceptionHelper   : 
SQL Error: 17026, SQLState: 99999
2020-02-18 15:24:13.662 ERROR 16476 --- [           main] o.h.engine.jdbc.spi.SqlExceptionHelper   : 
Numeric Overflow
2020-02-18 15:24:13.668  WARN 16476 --- [           main] ConfigServletWebServerApplicationContext : 
Exception encountered during context initialization - cancelling refresh attempt: 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'entityManagerFactory' defined in class path resource 
[org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init 
method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] 
Unable to build Hibernate SessionFactory; nested exception is 
org.hibernate.exception.GenericJDBCException: Unable to build DatabaseInformation
2020-02-18 15:24:13.668  INFO 16476 --- [           main] com.zaxxer.hikari.HikariDataSource       : 

Error starting ApplicationContext. To display the conditions report re-run your application with 
'debug' enabled.
2020-02-18 15:24:13.702 ERROR 16476 --- [           main] o.s.boot.SpringApplication               : 
Application run failed

java.sql.SQLException: Numeric Overflow
at oracle.jdbc.driver.NumberCommonAccessor.throwOverflow(NumberCommonAccessor.java:4170) ~[ojdbc6- 
11.2.0.4.0.jar:12.1.0.1.0]

这是我的 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema- 
instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven- 
     4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.4.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>ibbl.lu</groupId>
<artifactId>microservice_lims</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>microservice_lims</name>
<description>Demo project for Spring Boot</description>

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <!-- ojdbc6.jar example -->
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0.4.0</version>
    </dependency>

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

这是我的 application.properties

spring.jpa.hibernate.ddl-auto=update
spring.datasource.url= jdbc:oracle:thin:@Oracle-dev.xxx.xx.xx:1521:LBVT
spring.datasource.username=xxxx
spring.datasource.password=xxx!
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.jpa.show-sql=true

有人对这个问题有想法吗? 我已经下载了 ojdbc6.jar 并使用 maven 命令安装驱动程序 任何线索都会有所帮助

【问题讨论】:

标签: spring-boot oracle11g


【解决方案1】:

问题是由于ALL_sequence中的MAX_VALUE过大, 这就是为什么我有这个错误

java.sql.SQLException: Numeric Overflow

我将这个问题修复如下: 我创建了一个自定义类,它扩展了 Oracle10gDialect 并在 ALL_SEQUENCES 中重新定义了 MIN_VALUE、MAX_VALUE、 这是我的课

package ibbl.lu.microservice_lims.config;

import org.hibernate.dialect.Oracle10gDialect;

public class CustomOracleDialect extends Oracle10gDialect {

    @Override
    public String getQuerySequencesString() {
        return "SELECT SEQUENCE_OWNER, SEQUENCE_NAME, 
                greatest(MIN_VALUE,-9223372036854775807) MIN_VALUE,\n" +
                "Least(MAX_VALUE, 9223372036854775808) MAX_VALUE, 
                INCREMENT_BY,CYCLE_FLAG, ORDER_FLAG, CACHE_SIZE,\n" +
                "Least(greatest(LAST_NUMBER, -9223372036854775807), 
                9223372036854775808) LAST_NUMBER from ALL_SEQUENCES";
    }
}

在 application.properties 文件中引用了一个方言实现

spring.jpa.properties.hibernate.dialect=ibbl.lu.microservice_lims.config.CustomOracleDialect

【讨论】:

    猜你喜欢
    • 2021-10-16
    • 2019-06-15
    • 2020-12-26
    • 1970-01-01
    • 2018-10-10
    • 2022-10-02
    • 2022-01-11
    • 2020-02-26
    • 2019-04-03
    相关资源
    最近更新 更多