Guide to configure JNDI datasource in ColdFusion

July 30, 2019
I am working with ColdFusion Support team.
Staff 3 posts
Followers: 2 people
3

Guide to configure JNDI datasource in ColdFusion

I am working with ColdFusion Support team.
Staff 3 posts
Followers: 2 people
July 30, 2019

Here’s a guide to show you how to configure JNDI datasource in ColdFusion 2018.

1. Get the JDBC Driver

The JDBC Driver needs to be placed in ColdFusion2018/cfusion/lib folder.

2. context.xml configuration

Add a resource block before the closing tag </Context> in the context.xml present at ColdFusion2018/cfusion/runtime/conf , which defines database connection detail :

<Resource name=”jdbc/test” auth=”Container” type=”javax.sql.DataSource”

maxActive=”50″ maxIdle=”30″ maxWait=”10000″

username=”username” password=”password”

driverClassName=”com.mysql.jdbc.Driver”

url=”jdbc:mysql://localhost:3306/test”/>

For more information on the attributes please refer to https://tomcat.apache.org/tomcat-9.0-doc/jndi-datasource-examples-howto.html. For setting isolation level use the defaultTransactionIsolation attribute.

3. web.xml configuration

In the web.xml present at ColdFusion10/cfusion/wwwroot/WEB-INF , add the following just before the closing tag (</web-app>)

<resource-ref>

<description>MySQL Datasource example</description>

<res-ref-name>jdbc/test</res-ref-name>

<res-type>javax.sql.DataSource</res-type>

<res-auth>Container</res-auth>

</resource-ref>

4. Add ColdFusion DataSource through Administrator

After saving the configuration files restart the ColdFusion server. Log into ColdFusion Administrator and navigate to Data & Services > Data Sources and add a new Data Source by selecting J2EE Data Source(JNDI) in the driver dropdown. For more details on this refer https://helpx.adobe.com/in/coldfusion/configuring-administering/data-source-management-for-coldfusion.html#ConnectingtoJNDIdatasources

 

*Here I copied the content from this blog by Krishna for adding the Datasource in ColdFusion Administrator. Blog link: https://coldfusion.adobe.com/2015/07/configuring-jndi-data-sources-in-coldfusion/

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
the source is configured.
It should be left blank when the credentials are not required by the
server.

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.

  • Note: This can be followed in CF10, CF11, CF2016 and CF2018 releases.

Hope you found this useful.

Comments (3)
2019-07-30 15:53:33
2019-07-30 15:53:33

Interesting, Priyank. Can you offer a sentence or two about what scenarios may lead one to want to do this? Is there some benefit to using a JNDI-defined datasource, where a CF-provided one (or the “other JDBC” option) won’t work for folks? I just ask because I’d hate to see some folks think this is something they SHOULD do, when the existing options may suffice.

Perhaps you had a user who had a real need for this. I’m just saying it would be helpful to hear the need, as well as this solution to it. 🙂 Thanks.

Like
(2)
>
Charlie Arehart
's comment
2019-07-30 16:29:24
2019-07-30 16:29:24
>
Charlie Arehart
's comment

Hi Charlie,

We have users who still would like to use JNDI data source who are either migrating from WebSphere environment to Standalone installation of CF. We offered them to use the JDBC option however they want to stick to JNDI data source.

I don’t see any benefit over “Other JDBC”. Maybe the way users have written their application calling the JNDI. I published this blog because the old blog was deleted during the migration.

Like
>
Priyank Shrivastava
's comment
2019-07-31 03:56:08
2019-07-31 03:56:08
>
Priyank Shrivastava
's comment

Great. That explains it reasonably. Thanks.

Like
Add your comment