Tomcat - MySQL Connection Refused Errors Upon Initial Startup

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.
bigharAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ahoffmannCommented:
could it be that mysql is not fully running when tomcat starts?
Or do you have firewall restrictions?
0
bigharAuthor Commented:
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
ahoffmannCommented:
> ..  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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bigharAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.