title: org.hibernate.exception.JDBCConnectionException: Could not open connection exception in MySQL
body: <p>I have setup a mysql instance onto my local machine and using it with my java hibernate application on GAE. It was perfectly working, but since the afternoon it has started giving me error given below. Please help me figure out how to fix this. I am stuck and cannot proceed in code without any db transactions. Thanks!</p>
  
  <pre><code>org.hibernate.exception.JDBCConnectionException: Could not open connection
      at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:131)
      at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
      at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:304)
      at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:169)
      at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.extractPhysicalConnection(ConnectionProxyHandler.java:82)
      at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.continueInvocation(ConnectionProxyHandler.java:138)
      at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
      at com.sun.proxy.$Proxy47.prepareStatement(Unknown Source)
      at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:147)
      at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:166)
      at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:145)
      at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1711)
      at org.hibernate.loader.Loader.doQuery(Loader.java:828)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)
      at org.hibernate.loader.Loader.doList(Loader.java:2438)
      at org.hibernate.loader.Loader.doList(Loader.java:2424)
      at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2254)
      at org.hibernate.loader.Loader.list(Loader.java:2249)
      at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:470)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
      at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
      at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1248)
      at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
      at com.bullbeardevice.dao.impl.UserManagementDAOImpl.getUserRegistrationList(UserManagementDAOImpl.java:39)
      at com.bullbeardevice.service.impl.UserManagementServiceImpl.checkUserAlreadyRegistered(UserManagementServiceImpl.java:111)
      at com.bullbeardevice.controller.user.UserManagementController.registerUser(UserManagementController.java:38)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115)
      at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
      at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:100)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:604)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:565)
      at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
      at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
      at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:119)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:127)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366)
      at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:349)
      at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
      at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
      at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
      at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
      at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
      at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:98)
      at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:490)
      at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      at org.mortbay.jetty.Server.handle(Server.java:326)
      at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
      at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
      at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
      at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
      at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
      at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
      at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
  Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
  
  Last packet sent to the server was 0 ms ago.
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
      at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance_(Runtime.java:127)
      at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance(Runtime.java:135)
      at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
      at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
      at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2103)
      at com.mysql.jdbc.ConnectionImpl.&lt;init&gt;(ConnectionImpl.java:718)
      at com.mysql.jdbc.JDBC4Connection.&lt;init&gt;(JDBC4Connection.java:46)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
      at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance_(Runtime.java:127)
      at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance(Runtime.java:135)
      at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
      at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
      at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
      at java.sql.DriverManager.getConnection(DriverManager.java:571)
      at java.sql.DriverManager.getConnection(DriverManager.java:187)
      at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:173)
      at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:164)
      at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:149)
      at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:119)
      at org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:141)
      at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:281)
      at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:297)
      ... 78 more
  Caused by: java.net.SocketException: Socket operation timed out: The API call remote_socket.CreateSocket() took too long to respond and was cancelled.
      at com.google.appengine.api.socket.SocketApiHelper.makeSyncCall(SocketApiHelper.java:73)
      at com.google.appengine.api.socket.AppEngineSocketImpl.createSocket(AppEngineSocketImpl.java:466)
      at com.google.appengine.api.socket.AppEngineSocketImpl.connectToAddress(AppEngineSocketImpl.java:340)
      at com.google.appengine.api.socket.AppEngineSocketImpl.connect(AppEngineSocketImpl.java:332)
      at java.net.Socket.connect(Socket.java:579)
      at java.net.Socket.connect(Socket.java:528)
      at java.net.Socket.&lt;init&gt;(Socket.java:425)
      at java.net.Socket.&lt;init&gt;(Socket.java:241)
      at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:253)
      at com.mysql.jdbc.MysqlIO.&lt;init&gt;(MysqlIO.java:280)
      at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2026)
  
  
  
  
  
  
  
  &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
          xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
          xsi:schemaLocation="
              http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
              http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
              http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
              http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"&gt;
  
  &lt;context:component-scan base-package="com.bullbeardevice.*" /&gt; 
  
  
    &lt;!-- Hibernate Session Factory --&gt;
  &lt;bean id="propertyConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
          &lt;property name="locations"&gt;
              &lt;list&gt;
                  &lt;value&gt;classpath:database.properties&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="${db.driverClassName}" /&gt;
          &lt;property name="url" value="${db.url}" /&gt;
          &lt;property name="username" value="${db.username}" /&gt;
          &lt;property name="password" value="${db.password}" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="packagesToScan" value="com.bullbeardevice.model" /&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
              &lt;prop key="hibernate.dialect"&gt;${hibernate.dialect}&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;${hibernate.show_sql}&lt;/prop&gt;
                  &lt;prop key="hibernate.jdbc.batch_size"&gt;100&lt;/prop&gt;
                  &lt;!-- &lt;prop key="hibernate.hbm2ddl.auto"&gt;create-drop&lt;/prop&gt;  --&gt;
                  &lt;prop key="hibernate.current_session_context_class"&gt;
                      org.springframework.orm.hibernate4.SpringSessionContext
                  &lt;/prop&gt;
                  &lt;!-- configuration pool via c3p0 --&gt;
                  &lt;prop key="hibernate.c3p0.acquire_increment"&gt;5&lt;/prop&gt;
                  &lt;prop key="hibernate.c3p0.idle_test_period"&gt;600&lt;/prop&gt;
                  &lt;prop key="hibernate.c3p0.max_size"&gt;25&lt;/prop&gt;
                  &lt;prop key="hibernate.c3p0.max_statements"&gt;25&lt;/prop&gt;
                  &lt;prop key="hibernate.c3p0.min_size"&gt;5&lt;/prop&gt;
                  &lt;prop key="hibernate.c3p0.timeout"&gt;300&lt;/prop&gt;
                  &lt;prop key="hibernate.connection.release_mode"&gt;auto&lt;/prop&gt;
                  &lt;prop key="hibernate.auto_close_session"&gt;true&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
      &lt;bean id="transactionManager"
          class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
      &lt;/bean&gt;
    &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
  
    &lt;/beans&gt;
  
  db.driverClassName=com.mysql.jdbc.Driver
  #db.url=jdbc:mysql://192.168.1.2:3306/bullbeardevice
  db.url=jdbc:mysql://localhost:3306/bullbeardevice
  #db.url=jdbc:Oracle:thin:@127.0.0.1:1521/XE
  db.username=bullbeardevice
  db.password=bullbeardevice
  #hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
  hibernate.dialect=org.hibernate.dialect.MySQLDialect
  hibernate.show_sql=true
  hibernate.cache.use_second_level_cache=false
  hibernate.cache.use_query_cache=false
  #hibernate.cache.provider_class=net.sf.ehcache.hibernate.EhCacheProvider
  #hibernate.cache.provider_class==org.hibernate.cache.EhCacheProvider
  #db.sid=XE
  # configuration for hibernate search
  hibernate.search.default.locking_strategy=simple
  #hibernate.search.analyzer=org.apache.lucene.analysis.en.EnglishAnalyzer
  hibernate.search.worker.batch_size=100
  hibernate.search.indexing_strategy = manual
  hibernate.search.default.reader.strategy = shared
  hibernate.search.default.worker.thread_pool.size=30
  hibernate.search.default.indexwriter.ram_buffer_size=10
  hibernate.search.default.indexwriter.merge_max_optimize_size=7
  hibernate.search.default.indexwriter.merge_max_size=7
  </code></pre>