异常:oracle.jdbc.driver.T4CConnection.isValid(I)Z 尝试使用 Spring 引导访问 Oracle 时
Exception: oracle.jdbc.driver.T4CConnection.isValid(I)Z When trying to access Oracle using Spring Boot
我正在尝试 运行 示例 spring 使用 oracle 11g xe 启动 jpa 应用程序。我收到错误消息:java.lang.AbstractMethodError: oracle.jdbc.driver.T4CConnection.isValid(I)Z.
我正在使用以下内容:
Java8
Oracle xe 11.2.0
Spring2.4.0
下面是一些代码片段和详细信息:
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
主要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 详细信息
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.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
我已经尝试过以下,但收到同样的错误:
- 更改 Spring 引导和 ojdbc 的版本
- 正在下载 ojdbc8 jar 并将其添加为系统路径
任何人都可以帮忙解决这个问题。
您的 class 路径中一定有一些旧版本的 ojdbc jar,尝试删除所有旧版本 jdbc jar 并升级到 ojdbc 8 罐。这应该可以解决问题。
我正在尝试 运行 示例 spring 使用 oracle 11g xe 启动 jpa 应用程序。我收到错误消息:java.lang.AbstractMethodError: oracle.jdbc.driver.T4CConnection.isValid(I)Z.
我正在使用以下内容:
Java8
Oracle xe 11.2.0
Spring2.4.0
下面是一些代码片段和详细信息:
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
主要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 详细信息
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.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
我已经尝试过以下,但收到同样的错误:
- 更改 Spring 引导和 ojdbc 的版本
- 正在下载 ojdbc8 jar 并将其添加为系统路径
任何人都可以帮忙解决这个问题。
您的 class 路径中一定有一些旧版本的 ojdbc jar,尝试删除所有旧版本 jdbc jar 并升级到 ojdbc 8 罐。这应该可以解决问题。