Using CFMX 6.1 datasources from Java code

Some of the changes in CFMX 6.1 had the unfortunate side-effect of no longer enabling access to CF datasources through JNDI. The official solution to this is to use CFMX 4 J2EE and set up datasources through the underlying J2EE server.

Turns out this drastic change is not absolutely necessary. fozizzle posted a code snippet in the web forums that retrieves a CFMX 6.1 datasource from Java.

public static Connection getUsingCFService(String datasource) {
DataSourceService ds =
coldfusion.server.ServiceFactory.getDataSourceService();
try {
return ds.getDatasource(datasource).getConnection();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}

Nice find!

Picked up from Macromedia webforums.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>