The simplistic database connection setup with a
database.properties file, as described in the preceding sections, is suitable for small test programs but won’t scale for larger applications.
When a JDBC application is deployed in a web or enterprise environment, the management of database connections is integrated with the JNDI. The properties of data sources across the enterprise can be stored in a directory. Using a directory allows for centralized management of user names, passwords, database names, and JDBC URLs.
In such an environment, you can use the following code to establish a database connection:
Context jndiContext = new InitialContext(); ...