Accessing a ColdFusion Data Source from Java Code

I have a servlet that I would like to run in ColdFusion MX 7. I would like to use an existing ColdFusion DSN as javax.sql.DataSource, if possible.

I thought something like

coldfusion.server.ServiceFactory.getDataSourceService().getDatasource(dsname);

      

will work, but unfortunately the servlet returns

java.lang.NoClassDefFoundError: coldfusion/server/ServiceFactory

      

+1


source to share


2 answers


It seems like the easiest way to do this is to add an additional JNDI datasource to jrun-resources.xml. This can then be obtained in the usual way:

Context context = new InitialContext();
DataSource ds = (DataSource)context.lookup("mydatasource"); 

      



This means duplicating the database connection configuration, but I would rather do that than work with the undocumented coldfusion.server classes. *.

0


source


This code will work fine, you just don't have a ServiceFactory in your classpath. Those. Java cannot load this class. Try to include the cfusion.jar dependency from C: \ CFusionMX7 \ lib.



+1


source







All Articles