Home > Back-end >  Exception: oracle.jdbc.driver.T4CConnection.isValid(I)Z When trying to access Oracle using Spring Bo
Exception: oracle.jdbc.driver.T4CConnection.isValid(I)Z When trying to access Oracle using Spring Bo

Time:10-31

I'm trying to run a sample spring boot jpa application using oracle 11g xe. I'm getting error: java.lang.AbstractMethodError: oracle.jdbc.driver.T4CConnection.isValid(I)Z.

I'm using following:
Java 8
Oracle xe 11.2.0
Spring 2.4.0

Below is few code snippet and detail:

POM.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.0</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <java.version>1.8</java.version>
</properties>
<dependencies>
    <dependency>
        <groupId>com.oracle.database.jdbc</groupId>
        <artifactId>ojdbc8</artifactId>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
</dependencies>

Application.properties

spring.datasource.url=jdbc:oracle:thin:@voided-pc:1521:xe
spring.datasource.username=local
spring.datasource.password=oracle
spring.datasource.driverClassName=oracle.jdbc.OracleDriver 
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect

Main Class

    @SpringBootApplication
public class OracleApplication implements CommandLineRunner{
    
    @Autowired
    private JdbcTemplate jdbc;

    public static void main(String[] args) {
        SpringApplication.run(OracleApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        
        String sql = "select * from emp";
        List<Emp> res = jdbc.query(sql, BeanPropertyRowMapper.newInstance(Emp.class));
        System.out.println(res);
    }

}

DTO

@Entity
@Table(name =  "Emp")
@Getter @Setter
public class Emp implements Serializable{

    private static final long serialVersionUID = -8048548873630679159L;
    
    @Id
    @Column(name = "EMPNO", unique = true, nullable = false)
    private Long empNo;
    
    @Column(name = "ENAME")
    private String eName;
    
    @Column(name = "JOB")
    private String job;
    
    @Column(name = "MGR")
    private Long mgr;
    
    @Column(name = "HIREDATE")
    private Date hireDate;
    
    @Column(name = "SAL")
    private Double sal;
    
    @Column(name = "COMM")
    private Double comm;
    
    @Column(name = "DEPTNO")
    private Integer deptNo;
}

Oracle Details

C:\Users\new>lsnrctl status

LSNRCTL for 64-bit Windows: Version 11.2.0.2.0 - Production on 29-OCT-2021 02:06:23

Copyright (c) 1991, 2014, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for 64-bit Windows: Version 11.2.0.2.0 - Production
Start Date                28-OCT-2021 23:47:50
Uptime                    0 days 2 hr. 18 min. 33 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Default Service           XE
Listener Parameter File   C:\oraclexe\app\oracle\product\11.2.0\server\network\admin\listener.ora
Listener Log File         C:\oraclexe\app\oracle\diag\tnslsnr\voided-pc\listener\alert\log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1ipc)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=voided-pc)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=voided-pc)(PORT=8080))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "CLRExtProc" has 1 instance(s).
  Instance "CLRExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "PLSExtProc" has 1 instance(s).
  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "XEXDB" has 1 instance(s).
  Instance "xe", status READY, has 1 handler(s) for this service...
Service "xe" has 1 instance(s).
  Instance "xe", status READY, has 1 handler(s) for this service...
The command completed successfully

I have already tried following, but received same error:

  1. Changing version of Spring boot and ojdbc
  2. Downloading ojdbc8 jar and added that as system path

Could anyone, please help on this.

CodePudding user response:

You must be having some old release ojdbc jar in your class-path, try removing all the older release jdbc jars and upgrade to ojdbc8 jar. This should fix the problem.

  • Related