How to get coldfusion DataSource list programmatically

Get ColdFusion DataSource list programmatically

GetDataSourceList.cfm


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>DataSource List - how to get coldfusion DataSource list programmatically</title>
</head>

<body>
<h2 style="color:Crimson; font-style:italic">DataSource example: how to get DataSource list</h2>
<hr width="500" align="left" color="LightPink" />
<br />

<cfobject 
 action="create"
    type="java"
    class="coldfusion.server.ServiceFactory" 
    name="cfactory"
    >
<cfset DSourceStruct=cfactory.getDataSourceService().getDataSources()>
<cfset DSourceList=StructKeyList(DSourceStruct,",")>


<table border="1" cellpadding="2" cellspacing="2" bordercolor="Pink" bgcolor="DeepPink" width="350">
 <tr style="color:Snow; font-weight:bold; font-size:large; font-family:'Courier New', Courier, monospace;" height="35">
     <td>
         ColdFusion DataSource List
        </td>
    </tr>
 <cfoutput>
        <cfloop index="i" list="#DSourceList#">
            <tr style="font-weight:bold; font-style:normal; color:Snow;">
                <td bgcolor="HotPink">
                    #i#
                </td>
            </tr>
            </cfloop>
        </cfoutput>
</table>

</body>
</html>