Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

While accessing MySql directly through php, I am able to connect to the database without issues.

Whereas, while I try to access MySql indirectly - with the help of a jar file which connects to MySql db, I am not able to connect from php.

I have tested this jar file from terminal and it works perfect and connects to the db.

In a nutshell, for connecting to the same db:

(1) php-mysql connection works perfect (2) jar - mysql connection works perfect (3) php - jar - mysql connection fails

Caling shell_exec("java -jar /var/www/html/nyk/app/webroot/Converter.jar $id"); from the php code, calls the jar file correctly and gets inside it. But, when the java code in jar file tries to connect to MySql, when it reaches the following line conn = DriverManager.getConnection(url + dbName, userName, password);, it gives the following exception:

Inside JAR file
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: 


MESSAGE: Permission denied


java.net.SocketException: Permission denied
    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:392)
    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:256)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
    at com.mysql.jdbc.Connection.createNewIO(Connection.java:2771)
    at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
    at java.sql.DriverManager.getConnection(DriverManager.java:571)
    at java.sql.DriverManager.getConnection(DriverManager.java:215)
    at com.nykkos.personalization.MysqlConnect.<init>(MysqlConnect.java:29)
    at com.nykkos.personalization.MyConnect.dbGenMusic(MyConnect.java:154)
    at com.nykkos.personalization.MyConnect.main(MyConnect.java:22)


The above exception happens Only When the jar file is executed from php. Whereas, when the jar file is called from a terminal, it connects to MySql without any issues as discussed above.

I am puzzled as to why this strange behavior occurs - ie; connects to db when jar called from terminal and gives exception when the same jar tries to connect from php.

My operating system is fedora and server from php runs is Apache.

Has it got something to do with any configuration settings or is it something wrong which I do above causes this?

I have been after this issue googling all over the net to no avail, for the past two days.

I would really appreciate, if someone could get me out of this blocker.

Thanks in advance.

share|improve this question
How is the php code (which calls the jar) run? From the command line or through a web server? –  user1039462 Jul 9 '13 at 13:31
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.