gpt4 book ai didi

java - 未实现 Postgres 错误方法 org.postgresql.jdbc.PgConnection.createClob()

转载 作者:太空狗 更新时间:2023-10-29 22:39:26 53 4
gpt4 key购买 nike

当我使用连接对象调用 createClob 方法时,如下所示:

Clob clob = con.createClob();

抛出以下异常:

Caused by: java.sql.SQLFeatureNotSupportedException: Method org.postgresql.jdbc.PgConnection.createClob() is not yet implemented.
at org.postgresql.Driver.notImplemented(Driver.java:659)
at org.postgresql.jdbc.PgConnection.createClob(PgConnection.java:1246)
at org.apache.commons.dbcp2.DelegatingConnection.createClob(DelegatingConnection.java:868)
at org.apache.commons.dbcp2.DelegatingConnection.createClob(DelegatingConnection.java:868)

我正在使用带有 JDK8 的数据库 PostgreSQL 9.6.2 并使用 commons-dbcp2 连接池,并在 pom.xml 中添加了以下 Postgres 依赖项

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.1.1</version>
</dependency>

org.postgresql.jdbc.PgConnection 类中,createClob 实现如下所示,抛出异常:

@Override
public Clob createClob() throws SQLException {
checkClosed();
throw org.postgresql.Driver.notImplemented(this.getClass(), "createClob()");
}

克服此问题的解决方案或解决方法是什么?或者我们如何在 Postgres 查询中设置 CLOB 数据?

最佳答案

长话短说

  • 在您的 application.yml 中设置 spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true 或者,
  • persistence.xml 中设置 hibernate.jdbc.lob.non_contextual_creation=true

这是 JBoss 社区中的一个已知错误。

此错误出现在旧版本和 Spring-Boot 2.0.0.RC1 及更高版本的新版本中。

解决方案:

  1. 使用更新的向后兼容版本更新您的 postgressql 驱动程序。
    • 在您的 application.yml 中设置 spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true 或者,
    • 在您的 persistence.xml 中设置 hibernate.jdbc.lob.non_contextual_creation=true
  2. 如果它不起作用,请参阅下面的技巧:

解决方案是在您的属性文件中添加这一行(如果您不使用 spring,则添加类似的内容)

spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults= false

因此,您的 application.yml 应该如下所示:

spring:
application:
name: employee-service

datasource:
url: jdbc:postgresql://localhost:5432/db_development
platform: POSTGRESQL
username: ...
password: ...

jpa:
hibernate:
ddl-auto: create-drop
dialect: org.hibernate.dialect.PostgreSQL9Dialect
show_sql: true
properties.hibernate.temp.use_jdbc_metadata_defaults: false


server:
port: 8080

引用:

https://o7planning.org/en/11661/spring-boot-jpa-and-spring-transaction-tutorial

hibernate with c3p0: createClob() is not yet implemented

感谢 Binakot 的评论。我已经更新了帖子。

关于java - 未实现 Postgres 错误方法 org.postgresql.jdbc.PgConnection.createClob(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43905119/

53 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com