I am no Java expert. I do mostly M$ stuff, but I have dabbled. Java has a set of classes called JDBC and that stands for Java Database Connectivity. Those classes allow for variables to be passed and dynamic sql strings to concatenated and submitted to the database engine. How you read in your environment variable is going to be vendor and environment specific but it could done also in Java or anything you use for your application layer. Both are scalable when done and used correctly. You always want the right tool for the job or problem at hand.
School must be back in session.
If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry. Earnest Hemingway, A Farewell To Arms.