Getting a javax.sql.DataSource for a ColdFusion Datasource Name
On the DALNET #ColdFusion channel, a user needed to get a javax.sql.DataSource instance for use with a Java library, and wanted to use one of their configured ColdFusion datasources.
I've got a bit of code around for this kind of stuff, and thought it'd be handy to blog it in case anyone else needs to Google for the same type of functionality. The following UDF will do it, but it does make use of the largely undocumented ServiceFactory that underpins ColdFusion.
<cffunction name="getDataSource" output="false" hint="Gets the raw javax.sql.DataSource implementation for a given CF datasource name.">
<cfargument name="dsn" />
<cfset var svc = createObject("java", "coldfusion.server.ServiceFactory").DataSourceService>
<cfset var ds = svc.getDatasource(javacast("string", arguments.dsn)) />
<cfreturn ds />
</cffunction>
<cfargument name="dsn" />
<cfset var svc = createObject("java", "coldfusion.server.ServiceFactory").DataSourceService>
<cfset var ds = svc.getDatasource(javacast("string", arguments.dsn)) />
<cfreturn ds />
</cffunction>


There are no comments for this entry.
[Add Comment]