Using The CF Connection Pool In Java App
Andrew Powell
I was integrating a Java app into a CF app and ran into a little problem. I needed to pass the Java app's constructor a database connection object. I wanted to use the CF connection pool instead of creating a new connection to use just for the Java app. There was just one catch:
I didn't have the password for the datasource, and had no hope of getting it.
So goes the life of a consultant.
I had to look for another route to get the database connection without the password. It was time to get into a little ColdFusion ingenutiy. If ColdFusion is Java and is using JDBC connections, then there should be a way to access the connection via ColdFusion's java interfaces. There is. I found it by looking through the stack traces and a bit of trial and error. Anyways, here's what I came up with:
<cfscript>
var myConnection = createObject('java','coldfusion.server.ServiceFactory');
myConnection.getDataSourceService().getDatasource('myDSNName').getConnection();
var javaObj = createObject('java','path.to.object').init(myConnection)/>
javaObj.myMethod();
</cfscript>
Posted in ColdFusion | General | Adobe |
1 comments
Jun 12, 2008 at 12:53 PM Thank you for this post! Saved me some time digging around myself to find this information. Since using this approach have you run into any problems/gotchas?