Link to home
Start Free TrialLog in
Avatar of bighar
bighar

asked on

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.
Avatar of ahoffmann
ahoffmann
Flag of Germany image

could it be that mysql is not fully running when tomcat starts?
Or do you have firewall restrictions?
Avatar of bighar
bighar

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bighar

ASKER

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