(Originally written in Jul 2015, updated in Jan 2021)
For a more complete and updated discussion of this topic, see the 2019 post, Guide to configure JNDI datasource in ColdFusion.
This 2015 post below expanded on a still-older one, linked to below. Both are combined and updated into the more recent post.
For configuring JNDI data sources, it should firstly be supported by the application server.
Tomcat server, which is built-into ColdFusion server, has the support for this by default.
While there is a blog here on this how to configure, I want to explain few mistakes that are tend to be done while configuring.
One common mistake generally done is when the data source is configured from the ColdFusion administrator by
providing irrelevant username/password. You may tend to provide Database’s username/password. This is NOT
Database’s username/password. It is the application server’s username and password on which data
source is configured. It should be left blank when the credentials are not required by the
Prepending java:comp/env/ is required for the actual JNDI name that is registered in xml while registering the name in administrator.
It is not mandatory that you register the JNDI data source in ColdFusion administrator.
As long as the app server supports JNDI, you can invoke the data source that is configured in the application server in cfm source code directly either in case of standalone installation or EAR/WAR deployment. But for consistency and preferred names that can used in ColdFusion should be registered in ColdFusion.
This is applicable to both ColdFusion 10 and ColdFusion 11.