'Unable to connect to Postgress DB from shell script (through Java API)

I have implemented shell script which connect to Database to get data from table. Again These shell script invoked from Java API.

Flow : (Java API --> abc.sh(shell scipt) -> Postgress DB).

When I execute shell script manually from the server , it is able to connect to database but the same thing is not working when I make API call.

Here is the Piece code to connect to DB in the shell script :

VAR_email=psql -h hostname -d databasename -U user_name -p 5432 -a -w -AXqtc "select email from EMP where eid=10;"

What could be the issue, why my script is unable to DB when I make JAVA API call?

Is there any issue above code ? Please Help me out on this.

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source