Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Tomcat - MySQL Connection Refused Errors Upon Initial Startup

Posted on 2004-11-28
4
Medium Priority
?
667 Views
Last Modified: 2012-06-21
I'm running Tomcat 4.0.6 along with MySQL 4.1 on a Windows XP Pro laptop.  I have both MySQL and Tomcat services installed, configured to start up automatically when the machine starts.  I use the JDBC realm to do authentication against a MySQL database for one of my webapps.  I'm using the MySQL Connector/J version 3.0.16

The problem I'm having is that when I boot the laptop and go to acces my webapp, I get the following errors in the log:

Create Catalina server
Starting service Tomcat-Standalone
Apache Tomcat/4.0.6
Catalina.start: LifecycleException:  Exception opening database connection:  java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused: connect

** BEGIN NESTED EXCEPTION **

java.net.ConnectException
MESSAGE: Connection refused: connect

STACKTRACE:

java.net.ConnectException: Connection refused: connect
      at java.net.PlainSocketImpl.socketConnect(Native Method)
      at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
      at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
      at java.net.Socket.connect(Socket.java:452)
      at java.net.Socket.connect(Socket.java:402)
      at java.net.Socket.<init>(Socket.java:309)
      at java.net.Socket.<init>(Socket.java:124)
      at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:124)
      at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:225)
      at com.mysql.jdbc.Connection.createNewIO(Connection.java:1783)
      at com.mysql.jdbc.Connection.<init>(Connection.java:450)
      at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
      at org.apache.catalina.realm.JDBCRealm.open(JDBCRealm.java:548)
      at org.apache.catalina.realm.JDBCRealm.start(JDBCRealm.java:613)
      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1108)
      at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:343)
      at org.apache.catalina.core.StandardService.start(StandardService.java:388)
      at org.apache.catalina.core.StandardServer.start(StandardServer.java:506)
      at org.apache.catalina.startup.CatalinaService.start(CatalinaService.java:261)
      at org.apache.catalina.startup.CatalinaService.execute(CatalinaService.java:172)
      at org.apache.catalina.startup.Catalina.process(Catalina.java:179)
      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:324)
      at org.apache.catalina.startup.BootstrapService.main(BootstrapService.java:428)


** END NESTED EXCEPTION **


LifecycleException:  Exception opening database connection:  java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused: connect

** BEGIN NESTED EXCEPTION **

java.net.ConnectException
MESSAGE: Connection refused: connect

STACKTRACE:

java.net.ConnectException: Connection refused: connect
      at java.net.PlainSocketImpl.socketConnect(Native Method)
      at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
      at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
      at java.net.Socket.connect(Socket.java:452)
      at java.net.Socket.connect(Socket.java:402)
      at java.net.Socket.<init>(Socket.java:309)
      at java.net.Socket.<init>(Socket.java:124)
      at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:124)
      at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:225)
      at com.mysql.jdbc.Connection.createNewIO(Connection.java:1783)
      at com.mysql.jdbc.Connection.<init>(Connection.java:450)
      at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
      at org.apache.catalina.realm.JDBCRealm.open(JDBCRealm.java:548)
      at org.apache.catalina.realm.JDBCRealm.start(JDBCRealm.java:613)
      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1108)
      at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:343)
      at org.apache.catalina.core.StandardService.start(StandardService.java:388)
      at org.apache.catalina.core.StandardServer.start(StandardServer.java:506)
      at org.apache.catalina.startup.CatalinaService.start(CatalinaService.java:261)
      at org.apache.catalina.startup.CatalinaService.execute(CatalinaService.java:172)
      at org.apache.catalina.startup.Catalina.process(Catalina.java:179)
      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:324)
      at org.apache.catalina.startup.BootstrapService.main(BootstrapService.java:428)


** END NESTED EXCEPTION **


      at org.apache.catalina.realm.JDBCRealm.start(JDBCRealm.java:615)
      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1108)
      at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:343)
      at org.apache.catalina.core.StandardService.start(StandardService.java:388)
      at org.apache.catalina.core.StandardServer.start(StandardServer.java:506)
      at org.apache.catalina.startup.CatalinaService.start(CatalinaService.java:261)
      at org.apache.catalina.startup.CatalinaService.execute(CatalinaService.java:172)
      at org.apache.catalina.startup.Catalina.process(Catalina.java:179)
      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:324)
      at org.apache.catalina.startup.BootstrapService.main(BootstrapService.java:428)
----- Root Cause -----
java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused: connect

** BEGIN NESTED EXCEPTION **

java.net.ConnectException
MESSAGE: Connection refused: connect

STACKTRACE:

java.net.ConnectException: Connection refused: connect
      at java.net.PlainSocketImpl.socketConnect(Native Method)
      at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
      at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
      at java.net.Socket.connect(Socket.java:452)
      at java.net.Socket.connect(Socket.java:402)
      at java.net.Socket.<init>(Socket.java:309)
      at java.net.Socket.<init>(Socket.java:124)
      at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:124)
      at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:225)
      at com.mysql.jdbc.Connection.createNewIO(Connection.java:1783)
      at com.mysql.jdbc.Connection.<init>(Connection.java:450)
      at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
      at org.apache.catalina.realm.JDBCRealm.open(JDBCRealm.java:548)
      at org.apache.catalina.realm.JDBCRealm.start(JDBCRealm.java:613)
      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1108)
      at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:343)
      at org.apache.catalina.core.StandardService.start(StandardService.java:388)
      at org.apache.catalina.core.StandardServer.start(StandardServer.java:506)
      at org.apache.catalina.startup.CatalinaService.start(CatalinaService.java:261)
      at org.apache.catalina.startup.CatalinaService.execute(CatalinaService.java:172)
      at org.apache.catalina.startup.Catalina.process(Catalina.java:179)
      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:324)
      at org.apache.catalina.startup.BootstrapService.main(BootstrapService.java:428)


** END NESTED EXCEPTION **


      at com.mysql.jdbc.Connection.createNewIO(Connection.java:1851)
      at com.mysql.jdbc.Connection.<init>(Connection.java:450)
      at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
      at org.apache.catalina.realm.JDBCRealm.open(JDBCRealm.java:548)
      at org.apache.catalina.realm.JDBCRealm.start(JDBCRealm.java:613)
      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1108)
      at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:343)
      at org.apache.catalina.core.StandardService.start(StandardService.java:388)
      at org.apache.catalina.core.StandardServer.start(StandardServer.java:506)
      at org.apache.catalina.startup.CatalinaService.start(CatalinaService.java:261)
      at org.apache.catalina.startup.CatalinaService.execute(CatalinaService.java:172)
      at org.apache.catalina.startup.Catalina.process(Catalina.java:179)
      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:324)
      at org.apache.catalina.startup.BootstrapService.main(BootstrapService.java:428)

If I restart Tomcat manually, the problem doesn't return.  I'm pretty much at a loss as to where to start to solve this.

Thanks in advance for any assistance.
0
Comment
Question by:bighar
  • 2
  • 2
4 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 12693777
could it be that mysql is not fully running when tomcat starts?
Or do you have firewall restrictions?
0
 

Author Comment

by:bighar
ID: 12695830
I have Window's firewall turned off, and no other third party one installed.  Both MySQL and Tomcat are running when the machine starts.  What their start order is however, I'm not sure nor do I know how I would go about checking that.
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 2000 total points
ID: 12696141
> ..  nor do I know how I would go about checking that
sorry I don't know either ('cause in UNIX noone would ever ask about such simple things:-))
Either you use a script to start tomcat which has a delay or checks weither mysql is up, or you need to start tomcat manually..
0
 

Author Comment

by:bighar
ID: 12696474
I created a batch file to start Tomcat and set that to run when Windows starts.  Errors are gone.  Thanks for the idea ahoffmann.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month15 days, 1 hour left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question