2

我正在尝试将项目从 Java 8 迁移到使用 ojdbc 的 Java 11。我正在使用一个扩展 PoolDataSourceImpl 的类,该类实现了 PooLDataSource,它扩展了 javax.sql.DataSource,并且在尝试使用 maven 构建它时出现此错误:

编译失败 [ERROR] createConnectionBuilder() in oracle.ucp.jdbc.PoolDataSourceImpl 无法实现 create ConnectionBuilder() in javax.sql.DataSource [ERROR] 返回类型 oracle.ucp.jdbc.UCPConnectionBuilder 与 java.sql.ConnectionBuilder 不兼容

有没有人有什么建议?

4

4 回答 4

1

This is interface incompatibility. javax.sql.DataSource defines a method

default ConnectionBuilder createConnectionBuilder() throws SQLException

And as per the contract the return value requires to be of type ConnectionBuilder.

If you take a look at documentation of oracle.ucp.jdbc.PoolDataSourceImpl, it defines the method as

public UCPConnectionBuilder createConnectionBuilder()

whereas oracle.ucp.jdbc.UCPConnectionBuilder is not a subtype of java.sql.ConnectionBuilder.

Now unless Oracle releases a never version of oracle.ucp.jdbc.UCPConnectionBuilder interface that extends java.sql.ConnectionBuilder, you will not be able to interchange UCP PoolDataSource with javax.sql.DataSource.

The latest release at this point appears to be UCP 19.3, which would still hit the same problem which is unfortunate since 19.3 is advertised as JDK11 compliant. Please raise a bug against Oracle UCP to make the maintainers aware of the new entrant createConnectionBuilder in the DataSource interface.

In the intrim, if it is feasible, you may fall back to using 11g release 2 of UCP (not 12, not 19) which does not have the method createConnectionBuilder on the PoolDataSource interface. Not an ideal situation, since you are giving up on a decade worth of improvements in UCP by going back to 11g.

于 2020-04-16T12:22:00.583 回答
1

问题是您尝试继承 PoolDataSourceImpl 子类,这是一个使用 JDK8 编译的特定于供应商的类,我们不支持扩展我们的类,除非我们明确建议这样做,如在此博客中;这适用于所有软件供应商。由于此限制,我们的驱动程序(ojdbc8.jar、ucp.jar)与较新的 JDK 版本(即与 JDK11 一起使用)和数据库版本向前兼容。

于 2020-04-16T18:55:36.933 回答
0

在此问题下,在 PoolDataSource 上使用基于接口的代理进行代理将永远无法正常工作。在 oracle ucp 上记录了相同的错误。我什至在此https://community.oracle.com/thread/4325841上发布了一个没有回复的论坛查询。

于 2020-05-22T05:17:10.423 回答
0

此问题在 21.3 中通过 ucp11.jar(使用 JDK11 编译的 UCP 版本)解决。在这个版本中,UCPoracle.ucp.jdbc.UCPConnectionBuilder扩展了java.sql.ConnectionBuilder.

https://repo1.maven.org/maven2/com/oracle/database/jdbc/ucp/21.3.0.0/ucp-21.3.0.0.jar

于 2021-11-01T17:17:04.603 回答