Posted by Rahul in ColdFusion
While debugging one of the application tonight I doubted the issue could be the underlying database driver it was using. I thought that writing a tiny script to check the version of the Oracle JDBC driver that was used, like the one below would have done the trick
<cfscript>jdbcDriver = CreateObject("java", "oracle.jdbc.OracleDriver");writeoutput(jdbcDriver.getMajorVersion() &"."&jdbcDriver.getMinorVersion());</cfscript>
But to my disappointment this was not giving the results I expected.
Hence I started looking for a utility online that could help. I came across a few resources like this and this but all these talked about getting details from the ColdFusion database drivers(macromedia.jdbc.oracle.OracleDriver) which are different than the Oracle database thin drivers (oracle.jdbc.OracleDriver) I was using and wanted info on.
After spending a little more time on figuring this out, I can up wiith this snippet that helped me with what I was looking for.
<cfset oracleDriver=resolveResource()><cfif fileExists(oracleDriver)>Loaded from <cfoutput>#oracleDriver#</cfoutput><br><cftry><cfzip action="read" file="#oracleDriver#" entrypath="META-INF/MANIFEST.MF" variable="mainfest"><cfset line = listcontains(mainfest,"Specification-Version","#chr(13)#")><cfoutput>#listgetAt(mainfest, line, "#chr(13)#")#</cfoutput><cfcatch type="any">Unable to find version details</cfcatch></cftry><cfelse>Oracle Driver not Found !!</cfif><cffunction name="resolveResource" returnType="string"><cfargument name="resource" required="Yes" default="oracle/jdbc/OracleDriver.class"><cfset var resourceURL = getClass().getClassLoader().getResource(resource)><cfif isDefined("resourceURL")><cfreturn listlast(listfirst(resourceURL,"!"),":")></cfif><cfreturn ""></cffunction>
The above snippet fetches the version info from the manifest file of the jar where the version info is available for all oracle jdbc drivers. After utilizing <cfzip> earlier to get the list of ColdFusion tags the <cfzip> helped me with this one too.
I leveraged an existing function resolveResource() that we have to resolve from which jar a java class gets loaded. It is quite helpful in situations where there are conflicting classes (in different libraries or different version of the same lib) in the class path. resolveResource() is used to return the jar file location from where the object is loaded.