mercredi 30 septembre 2015

MySQL connection with tomcat works, standalone app doesn't

In AWS I have a tomcat application that successfully connects to our DB. I also have a cron job that I'm running by running it from the command line on the same AWS instance. Both use the same code to connect to the DB and the same property files. However, when I run from the command line on that instance I get this error:

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    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:525)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:343)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2132)
    ... 18 more
Caused by: java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    at java.net.Socket.connect(Socket.java:579)
    at java.net.Socket.connect(Socket.java:528)
    at java.net.Socket.<init>(Socket.java:425)
    at java.net.Socket.<init>(Socket.java:241)
    at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:253)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:292)
    ... 19 more
Exception in thread "main" java.lang.NullPointerException
    at com.api.spring.management.CheckStatus.getRequests(CheckStatus.java:135)
    at com.api.spring.management.CheckStatus.main(CheckStatus.java:120)

I put some debug in the application and the DB URL, name, username and password are the same in both. So, I'm not sure why running from command line doesn't work, but running it through tomcat does. Any ideas?




Aucun commentaire:

Enregistrer un commentaire