簡體   English   中英

c3p0和Heroku postgres,SSL問題

[英]c3p0 and Heroku postgres, issues with SSL

更新

無法連接到postgres數據庫。 postgres的依賴性是通過maven添加的。

Maven依賴

<dependency>
 <groupId>postgresql</groupId>
 <artifactId>postgresql</artifactId>
 <version>9.1-901-1.jdbc4</version>
</dependency>

Postgres池

public class PostgresDB implements DBPool {
public PostgresDB()  {
}

private static ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource();

static {
    try {
        Properties props = new Properties();
        props.setProperty("ssl", "false");
        comboPooledDataSource.setDriverClass( "org.postgresql.Driver" );
        comboPooledDataSource.setJdbcUrl("jdbc:postgresql://ec2-79-125-4-72.eu-west-1.compute.amazonaws.com:5432/d35hi5u7rnue7f");
        comboPooledDataSource.setUser("user");
        comboPooledDataSource.setPassword("xxxxxxxx");
        comboPooledDataSource.setProperties(props);
    } catch (Exception e) {
        System.out.println("Error");
        // handle the exception
    }
}

public Connection getConnection() throws SQLException {
    return comboPooledDataSource.getConnection();
}
}

獲取連接的代碼

Connection connection = PostgresDB.getConnection();

錯誤

警告:com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@2326357e - 獲取嘗試失敗!!! 清除待處理的收購。 在嘗試獲取所需的新資源時,我們未能成功超過允許的最大獲取嘗試次數(30)。 上次獲取嘗試異常:org.postgresql.util.PSQLException:Der Verbindungsversuch schlug fehl。 at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:152)org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)at org.postgresql.jdbc2.AbstractJdbc2Connection。(AbstractJdbc2Connection.java: 125)org.postgresql.jdbc3.AbstractJdbc3Connection。(AbstractJdbc3Connection.java:30)org.postgresql.jdbc3g.AbstractJdbc3gConnection。(AbstractJdbc3gConnection.java:22)at org.postgresql.jdbc4.AbstractJdbc4Connection。(AbstractJdbc4Connection.java:32) at org.postgresql.jdbc4.Jdbc4Connection。(Jdbc4Connection.java:24)atg.postgresql.Driver.makeConnection(Driver.java:393)atg.postgresql.Driver.connect(Driver.java:267)at com.mchange .v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:119)位於com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:143)com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataS) source.java:132)com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool $ 1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)at com .mchange.v2.resourcepool.BasicResourcePool.access $ 800(BasicResourcePool.java:32)at com.mchange.v2.resourcepool.BasicResourcePool $ AcquireTask.run(BasicResourcePool.java:1810)at com.mchange.v2.async.ThreadPoolAsynchronousRunner $ PoolThread.run(ThreadPoolAsynchronousRunner.java:547)引起:javax.net.ssl.SSLHandshakeException:PKIX路徑構建失敗:sun.security.provider.certpath.SunCertPathBuilderException:無法在java.base /中找到所請求目標的有效證書路徑位於java.base / sun.security.ssl.TransportContext的java.base / sun.security.ssl.TransportContext.fatal(TransportContext.java:321)中的sun.security.ssl.Alert.createSSLException(Alert.java:128)。 java.base / sun.security.ssl.TransportCo上的致命(TransportContext.java:264) ntext.fatal(TransportContext.java:259)位於java.base / sun.security.ssl.CertificateMessage $ T12CertificateConsumer.checkServerCerts(CertificateMessage.java:642),位於java.base / sun.security.ssl.CertificateMessage $ T12CertificateConsumer.onCertificate( CertificateMessage.java:461)java.base / sun.security.ssl.CertificateMessage $ T12CertificateConsumer.consume(CertificateMessage.java:361)at java.base / sun.security.ssl.SSLHandshake.consume(SSLHandshake.java:392) java.base / sun.security上java.base / sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:444)的java.base / sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:421) .ssl.TransportContext.dispatch(TransportContext.java:178)位於java.base / sun.security.ssl.SSLTransport.decode(SSLTransport.java:164)java.base / sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl) .java:1152)在java.base / sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1063)java.base / sun.security.ssl.SSLSocketImpl.startHandshake (SSLSocketImpl.java:402)java.base / sun.security.ssl.SSLSocketImpl.ensureNegotiated(SSLSocketImpl.java:716)at java.base / sun.security.ssl.SSLSocketImpl $ AppOutputStream.write(SSLSocketImpl.java:970) )java.base / java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:81)at java.base / java.io.BufferedOutputStream.flush(BufferedOutputStream.java:142)at org.postgresql.core.PGStream.flush( PGStream.java:523)org.postgresql.core.v3.ConnectionFactoryImpl.sendStartupPacket(ConnectionFactoryImpl.java:259)at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:105)... 16更多引起by:sun.security.validator.ValidatorException:PKIX路徑構建失敗:sun.security.provider.certpath.SunCertPathBuilderException:無法在java.base / sun.security.validator.PKIXValidator.doBuild(PKIXValidator)中找到所請求目標的有效證書路徑.java:385)at java.base / sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:290) java.base / sun.security上java.base / sun.security.validator.Validator.validate(Validator.java:264)的java.base / sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:321) .ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:221)位於java.base / sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:129),位於java.base / sun.security.ssl.CertificateMessage $ T12CertificateConsumer.checkServerCerts (CertificateMessage.java:626)... 33更多引起:sun.security.provider.certpath.SunCertPathBuilderException:無法在java.base / sun.security.provider.certpath.SunCertPathBuilder.build找到所請求目標的有效證書路徑(SunCertPathBuilder.java:141)位於java.base / java.security.cert.CertPathBuilder.build的java.base / sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126)(CertPathBuilder.java:297) )在java.base / sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:380)... 39更多

固定

如果您遇到同樣的問題,請將代碼更改為:

comboPooledDataSource.setJdbcUrl("jdbc:postgresql://url:port/database");

Properties props = new Properties();
props.setProperty("sslmode", "require");
props.setProperty("ssl", "true");
props.setProperty("sslfactory", "org.postgresql.ssl.NonValidatingFactory");
props.setProperty("user", "username");
props.setProperty("password", "xxxxxxx");
comboPooledDataSource.setProperties(props);

而不是props.setProperty("ssl", "false"); 嘗試:

props.setProperty("sslmode", "disable");

有關更多信息,請參閱Heroku 關於使用Java連接到 Heroku上的關系數據庫的文檔。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM