This discussion is archived
3 Replies Latest reply: Oct 24, 2012 1:49 PM by EJP RSS

Getting JDBC Connection exception... what is the problem

Madeline Newbie
Currently Being Moderated
I have connection problem and I get the following... Do you have any idea what it might be? Many thanks.

[java] org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
[java] The last packet successfully received from the server was 82 milliseconds ago. The last packet sent successfully to the server was 82 milliseconds ago.
[java]      at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:82)
[java]      at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:577)
[java]      at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:641)
[java]      at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:666)
[java]      at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:698)
[java]      at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.query(NamedParameterJdbcTemplate.java:133)
[java]      at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.query(NamedParameterJdbcTemplate.java:137)
[java]      at se.kth.ite.mss.KurserUtil.getSenasteValdaKurser(KurserUtil.java:71)
[java]      at org.apache.jsp.minasidor.kurser.nyaKurser_jsp._jspService(nyaKurser_jsp.java:91)
[java]      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
[java]      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
[java]      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
[java]      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
[java]      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
[java]      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
[java]      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
[java]      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
[java]      at se.kth.ite.portal.ContextLoggingFilter.doFilter(ContextLoggingFilter.java:53)
[java]      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
[java]      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
[java]      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
[java]      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
[java]      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
[java]      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
[java]      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
[java]      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
[java]      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
[java]      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
[java]      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
[java]      at java.lang.Thread.run(Thread.java:680)
[java] Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
[java] The last packet successfully received from the server was 82 milliseconds ago. The last packet sent successfully to the server was 82 milliseconds ago.
[java]      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[java]      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
[java]      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
[java]      at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
[java]      at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
[java]      at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1118)
[java]      at com.mysql.jdbc.ExportControlled.transformSocketToSSLSocket(ExportControlled.java:107)
[java]      at com.mysql.jdbc.MysqlIO.negotiateSSLConnection(MysqlIO.java:4553)
[java]      at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1330)
[java]      at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2312)
[java]      at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122)
[java]      at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774)
[java]      at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49)
[java]      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[java]      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
[java]      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
[java]      at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
[java]      at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
[java]      at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375)
[java]      at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289)
[java]      at java.sql.DriverManager.getConnection(DriverManager.java:582)
[java]      at java.sql.DriverManager.getConnection(DriverManager.java:185)
[java]      at org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS.getPooledConnection(DriverAdapterCPDS.java:205)
[java]      at org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS.getPooledConnection(DriverAdapterCPDS.java:150)
[java]      at org.apache.commons.dbcp.datasources.InstanceKeyDataSource.testCPDS(InstanceKeyDataSource.java:836)
[java]      at org.apache.commons.dbcp.datasources.SharedPoolDataSource.registerPool(SharedPoolDataSource.java:210)
[java]      at org.apache.commons.dbcp.datasources.SharedPoolDataSource.getPooledConnectionAndInfo(SharedPoolDataSource.java:169)
[java]      at org.apache.commons.dbcp.datasources.InstanceKeyDataSource.getConnection(InstanceKeyDataSource.java:701)
[java]      at org.apache.commons.dbcp.datasources.InstanceKeyDataSource.getConnection(InstanceKeyDataSource.java:676)
[java]      at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:113)
[java]      at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79)
[java]      ... 29 more
[java] Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
[java]      at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
[java]      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1764)
[java]      at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:241)
[java]      at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:235)
[java]      at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1206)
[java]      at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:136)
[java]      at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:593)
[java]      at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:529)
[java]      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:958)
[java]      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1203)
[java]      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1230)
[java]      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1214)
[java]      at com.mysql.jdbc.ExportControlled.transformSocketToSSLSocket(ExportControlled.java:92)
[java]      ... 53 more
[java] Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
[java]      at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:323)
[java]      at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:217)
[java]      at sun.security.validator.Validator.validate(Validator.java:218)
[java]      at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:126)
[java]      at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:209)
[java]      at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:249)
[java]      at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1185)
[java]      ... 61 more
[java] Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
[java]      at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:174)
[java]      at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:238)
[java]      at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:318)
[java]      ... 67 more
  • 1. Re: Getting JDBC Connection exception... what is the problem
    rp0428 Guru
    Currently Being Moderated
    >
    I have connection problem and I get the following... Do you have any idea what it might be?
    >
    It might be that you didn't post any code (using \
     tags) for anyone to look at.
    
    People can't debug code that they can't see.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
  • 2. Re: Getting JDBC Connection exception... what is the problem
    Joe Weinstein Expert
    Currently Being Moderated
    Do you get this every time, and never successfully connect, or do you get this only occasionally?
    If the former, I bet your login information (user/password etc) is wrong. Otherwise, it's either
    something to debug at the DBMS end, or least likely, a network/firewall issue. The stacktrace
    implies you're trying to connect via SSL, so that's something to look into that could cause
    your problem. If the DBMS isn't configured to handle SSL on the port you're connecting to...
  • 3. Re: Getting JDBC Connection exception... what is the problem
    EJP Guru
    Currently Being Moderated
    I have connection problem and I get the following... Do you have any idea what it might be?
    Yes, it's right there in the stack trace:
    [java] Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    Your client truststore doesn't trust the server's certificate.

    I must say Oracle don't make it easy by layering several more identical exceptions on top of it.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points