Nir*_*tel 18 java postgresql jdbc apache-commons-dbcp
当我使用连接对象调用createClob方法时,如下所示
Clob clob = con.createClob();
Run Code Online (Sandbox Code Playgroud)
抛出以下异常.
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)
Run Code Online (Sandbox Code Playgroud)
我正在使用带有JDK8的数据库PostgreSQL 9.6.2并使用commons-dbcp2连接池,并在pom.xml中添加了以下Postgres依赖项
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.1.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
在类中createClob,createClob实现如下所示,它抛出了异常.
@Override
public Clob createClob() throws SQLException {
checkClosed();
throw org.postgresql.Driver.notImplemented(this.getClass(), "createClob()");
}
Run Code Online (Sandbox Code Playgroud)
解决此问题的解决方案或解决方法是什么?或者我们如何在Postgres查询中设置CLOB数据?
Key*_*r00 29
TL; DR
设置spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true在你的application.yml
这是JBoss社区中的一个已知错误.
此错误出现在以前的版本和新版本的Spring-Boot 2.0.0.RC1以及更高版本中.
方案:
hibernate.jdbc.lob.non_contextual_creation=true在persistence.xml中设置解决方案是在您的属性文件中添加此行(如果您不使用spring,则为类似的行)
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults= false
Run Code Online (Sandbox Code Playgroud)
所以,你的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
Run Code Online (Sandbox Code Playgroud)
参考:
https://o7planning.org/en/11661/spring-boot-jpa-and-spring-transaction-tutorial
hibernate与c3p0:createClob()尚未实现