Method org.postgresql.jdbc4.Jdbc4Connection.isValid(int) is not yet implemented

后端 未结 7 757
时光说笑
时光说笑 2020-12-06 03:42

I am trying to configure dbcp2 with postgres 9.1

When I run my app, it throws exception:

Exception in thread \"main\" org.springframework.jdbc.Cannot         


        
相关标签:
7条回答
  • 2020-12-06 04:37

    Replace your postgresql with below entry in pom.xml. My Postgress version was postgresql-9.3.10-3.

    <dependency>
      <groupId>org.postgresql</groupId>
      <artifactId>postgresql</artifactId>
      <version>9.3-1100-jdbc41</version>
    </dependency>
    
    0 讨论(0)
  • 2020-12-06 04:37

    This ticket helped me to solve the issue: Caused by: java.lang.NoSuchMethodError: org.postgresql.core.BaseConnection.getEncoding()Lorg/postgresql/core/Encoding;

    Basically, you need to exclude PostGIS stubs:

     <dependency>
       <groupId>org.postgis</groupId>
       <artifactId>postgis-jdbc</artifactId>
       <version>1.3.3</version>
       <scope>compile</scope>
       <exclusions>
          <exclusion>
             <groupId>org.postgis</groupId>
             <artifactId>postgis-stubs</artifactId>
          </exclusion>
       </exclusions>
    </dependency>
    
    0 讨论(0)
  • 2020-12-06 04:38

    That method is implemented in the current driver version. You must be using an old PgJDBC. Upgrade. It's fully backward compatible. (You should've specified your PgJDBC version in the question).

    Separately, though, relying on connection "validation" is usually a bad idea. It's just a way of trying to imperfectly hide a race condition. Simply grab the connection and use it. If there's a problem with it, your application should trap the resulting exception, check the SQLSTATE to see if it's a connection related error, and retry with a new connection.

    0 讨论(0)
  • 2020-12-06 04:39

    Solution: Set a validation query for parameter "validationQuery".

    E.g for bean: property name="validationQuery" value="SELECT 1"

    This validation query is run against the connection before returning it. So have a valid query, above is a dummy one.

    https://commons.apache.org/proper/commons-dbcp/configuration.html

    0 讨论(0)
  • 2020-12-06 04:42

    Craig has right. The root cause is postgresql group id changed to org.postgresql and the old group doesn't get the updates. You should refresh your dependency node i.e.:

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

    according to the current latest version https://mvnrepository.com/artifact/org.postgresql/postgresql/

    0 讨论(0)
  • 2020-12-06 04:43

    Replace the POM.xml version to

    <dependency>
                <groupId>org.postgresql</groupId>
                <artifactId>postgresql</artifactId>
                <version>9.4-1200-jdbc41</version>
    </dependency>
    

    Also, if you are using SSL, the jdbc URL should be following format

    spring.datasource.url=jdbc:postgresql://hostName:5432/db?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory
    
    0 讨论(0)
提交回复
热议问题