aspose file tools*
The moose likes JDBC and the fly likes Tomcat error --> org.hibernate.exception.JDBCConnectionException: Cannot open connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Tomcat error --> org.hibernate.exception.JDBCConnectionException: Cannot open connection" Watch "Tomcat error --> org.hibernate.exception.JDBCConnectionException: Cannot open connection" New topic
Author

Tomcat error --> org.hibernate.exception.JDBCConnectionException: Cannot open connection

Elizabeth Liew
Greenhorn

Joined: Jun 04, 2008
Posts: 6
Hi all,

I am having problem with the JDBC connection in Tomcat using Hibernate and the database used is Microsoft SQL Server.This error will occur after sometimes of using the application. The problem can be solved if the tomcat is restarted but the problem is recurring and I will have to restart the tomcat again.

May I know that is there a possibilities that this happened because of the Microsoft SQL Server JDBC driver does not support an autoreconnect option?

How can i set autoreconnect = true like what the MySQL can do?

Does connection pooling setting in Hibernate help? Does the setting like below help?

<property name="c3p0.acquire_increment">5</property>
<property name="c3p0.idle_test_period">10</property>
<property name="c3p0.min_size">5</property>
<property name="c3p0.max_size">300</property>
<property name="c3p0.timeout">1</property>
<property name="c3p0.max_statements">300</property>


Appreciated if any one can help me to solve the issue. Thanks in advance.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2503
    
    8

Can you post your error information. This will help us to find the cause.
If possible, paste the complete error message you get in your application.

It is a bit odd that you get this info after a while, and not immediately.

Regards, Jan


OCUP UML fundamental and ITIL foundation
youtube channel
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

Elizabeth Liew wrote:This error will occur after sometimes of using the application.


Is the error you are getting when the first time the application tries to access the database? Check the tomcat logs and post the stack trace here.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Elizabeth Liew
Greenhorn

Joined: Jun 04, 2008
Posts: 6
Dear All,


Thanks for the response and sorry for late reply. This error does not occur during the first time application tries to access the DB.

The below are the stack trace. Really, thanks for the quick response.


2009-05-05 10:49:33 StandardContext[/jsp-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@33d8ce')
2009-05-05 10:49:33 StandardContext[/jsp-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@1deedb9')
2009-05-05 10:49:33 StandardContext[/jsp-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@c94402')
2009-05-05 10:49:33 StandardContext[/jsp-examples]SessionListener: contextDestroyed()
2009-05-05 10:49:33 StandardContext[/jsp-examples]ContextListener: contextDestroyed()
2009-05-05 10:49:34 StandardContext[/servlets-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@5fefcf')
2009-05-05 10:49:34 StandardContext[/servlets-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@790fa3')
2009-05-05 10:49:34 StandardContext[/servlets-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@1f1d526')
2009-05-05 10:49:34 StandardContext[/servlets-examples]SessionListener: contextDestroyed()
2009-05-05 10:49:34 StandardContext[/servlets-examples]ContextListener: contextDestroyed()
2009-05-05 10:50:19 StandardContext[/balancer]org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: [org.apache.webapp.balancer.RuleChain: [org.apache.webapp.balancer.rules.URLStringMatchRule: Target string: News / Redirect URL: http://www.cnn.com], [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: paramName / Target param value: paramValue / Redirect URL: http://www.yahoo.com], [org.apache.webapp.balancer.rules.AcceptEverythingRule: Redirect URL: http://jakarta.apache.org]]
2009-05-05 10:50:25 StandardHost[localhost]: Error deploying application at context path null
java.lang.IllegalStateException: Context path /job is already in use
at org.apache.commons.digester.Digester.createSAXException(Digester.java:2540)
at org.apache.commons.digester.Digester.createSAXException(Digester.java:2566)
at org.apache.commons.digester.Digester.endElement(Digester.java:1061)
at org.apache.catalina.util.CatalinaDigester.endElement(CatalinaDigester.java:76)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.emptyElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$ContentDispatcher.scanRootElementHook(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.commons.digester.Digester.parse(Digester.java:1567)
at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:488)
at org.apache.catalina.core.StandardHost.install(StandardHost.java:863)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:483)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:427)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:983)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:349)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1091)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:789)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478)
at org.apache.catalina.core.StandardService.start(StandardService.java:480)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:2313)
at org.apache.catalina.startup.Catalina.start(Catalina.java:556)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:287)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:425)

2009-05-05 10:50:25 StandardContext[/jsp-examples]ContextListener: contextInitialized()
2009-05-05 10:50:25 StandardContext[/jsp-examples]SessionListener: contextInitialized()
2009-05-05 10:50:25 StandardContext[/servlets-examples]ContextListener: contextInitialized()
2009-05-05 10:50:25 StandardContext[/servlets-examples]SessionListener: contextInitialized()
2009-05-05 11:08:40 StandardWrapperValve[action]: Servlet.service() for servlet action threw exception
org.hibernate.exception.JDBCConnectionException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:66)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:301)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:110)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:88)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1426)
at org.hibernate.loader.Loader.doQuery(Loader.java:637)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:221)
at org.hibernate.loader.Loader.doList(Loader.java:1858)
at org.hibernate.loader.Loader.list(Loader.java:1842)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1329)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:300)
at org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:433)
at com.mymcsb.ewms.entity.Company.findByName(Company.java:111)
at com.mymcsb.core.security.LoginAction.execute(LoginAction.java:68)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at com.mymcsb.base.ActionServlet.process(ActionServlet.java:41)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at com.mymcsb.core.security.SecurityFilter.doFilter(SecurityFilter.java:135)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:595)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host has failed. java.net.SocketException: No buffer space available (maximum connections reached?): JVM_Bind
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:298)
... 47 more

2009-05-05 11:27:50 StandardContext[/jsp-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@1df3d59')
2009-05-05 11:27:50 StandardContext[/jsp-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@134c5ff')
2009-05-05 11:27:50 StandardContext[/jsp-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@1b3278a')
2009-05-05 11:27:50 StandardContext[/jsp-examples]SessionListener: contextDestroyed()
2009-05-05 11:27:50 StandardContext[/jsp-examples]ContextListener: contextDestroyed()
2009-05-05 11:27:50 StandardContext[/servlets-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@704cf5')
2009-05-05 11:27:50 StandardContext[/servlets-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@cc7f9e')
2009-05-05 11:27:50 StandardContext[/servlets-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@1ce5e7a')
2009-05-05 11:27:50 StandardContext[/servlets-examples]SessionListener: contextDestroyed()
2009-05-05 11:27:50 StandardContext[/servlets-examples]ContextListener: contextDestroyed()
2009-05-05 11:35:44 StandardContext[/balancer]org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: [org.apache.webapp.balancer.RuleChain: [org.apache.webapp.balancer.rules.URLStringMatchRule: Target string: News / Redirect URL: http://www.cnn.com], [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: paramName / Target param value: paramValue / Redirect URL: http://www.yahoo.com], [org.apache.webapp.balancer.rules.AcceptEverythingRule: Redirect URL: http://jakarta.apache.org]]
2009-05-05 11:35:56 StandardHost[localhost]: Error deploying application at context path null
java.lang.IllegalStateException: Context path /job is already in use
at org.apache.commons.digester.Digester.createSAXException(Digester.java:2540)
at org.apache.commons.digester.Digester.createSAXException(Digester.java:2566)
at org.apache.commons.digester.Digester.endElement(Digester.java:1061)
at org.apache.catalina.util.CatalinaDigester.endElement(CatalinaDigester.java:76)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.emptyElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$ContentDispatcher.scanRootElementHook(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.commons.digester.Digester.parse(Digester.java:1567)
at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:488)
at org.apache.catalina.core.StandardHost.install(StandardHost.java:863)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:483)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:427)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:983)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:349)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1091)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:789)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478)
at org.apache.catalina.core.StandardService.start(StandardService.java:480)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:2313)
at org.apache.catalina.startup.Catalina.start(Catalina.java:556)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:287)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:425)

2009-05-05 11:35:56 StandardContext[/jsp-examples]ContextListener: contextInitialized()
2009-05-05 11:35:56 StandardContext[/jsp-examples]SessionListener: contextInitialized()
2009-05-05 11:35:56 StandardContext[/servlets-examples]ContextListener: contextInitialized()
2009-05-05 11:35:56 StandardContext[/servlets-examples]SessionListener: contextInitialized()
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

at java.lang.Thread.run(Thread.java:595)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host has failed.


I think this is the problem. First make sure your database is up and running and try to access that using simple java program.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2503
    
    8

Vijitha Kumara wrote:
at java.lang.Thread.run(Thread.java:595)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host has failed.


I think this is the problem. First make sure your database is up and running and try to access that using simple java program.
But the OP says that it works for a while, and fails later on.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

Hmm. I just check the stack trace not the original post when replying for the second time , my bad

By the way I found something similar here, that's of course for MySQL but it seems worth checking on that.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2503
    
    8

Vijitha Kumara wrote:
By the way I found something similar here, that's of course for MySQL but it seems worth checking on that.
Yes. The strange thing is that all info I found on the web - for this particular error - deals with the situation that the initial connection fails.
I've been trying to find possible causes for this error, and this is the list that popped up in my brain:
- intermittent networking issues
- Operating System/ Server restrictions: maximum number of tcp/ip connections reached on the server (maybe it's not a windows server, but a windows client, and it might have a limitation on the number of tcp/ip connections.
- sqlserver restrictions: the maximum number of connections is lower than the maximum limit in Elisabeth's program?
- connection leak: not all connections properly returned in the program?
Elizabeth Liew
Greenhorn

Joined: Jun 04, 2008
Posts: 6
Hi All,


Thanks for the reply. I guess you guys have your point. I am planning to configure the Hibernate connection pooling so that the idle connection will be closed. No sure this will work but will test it out.

Thanks guys.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tomcat error --> org.hibernate.exception.JDBCConnectionException: Cannot open connection