Saturday, January 12, 2008

Display Full ColdFusion JDBC Driver Versions on Screen (Windows O/S)

At some point or other, you may need to check ColdFusion's jdbc driver versions. I do it so infrequently I usually have resort to google to remember the process. Usually I use the instructions on Brandon Purcell's blog: How to determine the exact DataDirect driver versions

It works well, but I remember thinking there should be a way to print the full driver versions to the screen, instead of writing them to a log. While working working on a problem with cfexecute last week it occurred to me I could use cfexecute to do just that.

Drawing on a few tips from Ben Forta's blog, here is how to display the full driver version numbers on screen (windows o/s specific). Note, you may need to change the paths to the macromedia_drivers.jar and/or cmd.exe.


UPDATE: Dan G. Switzer, II made a few improvements to the code in his entry Display ColdFusion JDBC Drivers on Windows. Most notably replacing the hard coded paths I included for demonstration, with a root path from the server scope, making the code portable. I have updated this entry to reflect that one change. You can view the full version, with a few other additions, on his blog. Thanks Dan!


MX7 or higher (windows o/s)

<cfset driverInfo = arrayNew(1) >
<!--- UPDATE: replaced with dynamic path from server scope
<cfset pathToDriverJar = "C:\CFusionMX7\lib\macromedia_drivers.jar">
--->
<cfset pathToDriverJar = Server.ColdFusion.RootDir & "\lib\macromedia_drivers.jar">
<cfset drivernames = "macromedia.jdbc.oracle.OracleDriver, macromedia.jdbc.db2.DB2Driver, macromedia.jdbc.informix.InformixDriver, macromedia.jdbc.sequelink.SequeLinkDriver, macromedia.jdbc.sqlserver.SQLServerDriver, macromedia.jdbc.sybase.SybaseDriver">
<cfloop list="#driverNames#" index="driver">
<cfexecute name="C:\WINNT\system32\cmd.exe"
arguments="/c java -cp #pathToDriverJar# #driver# 2>&1"
variable="out"
timeout="6"
/>
<cfif IsDefined("out")>
<cfset data = structNew()>
<cfset data.class = driver>
<cfset data.version = out>
<cfset arrayAppend(driverInfo, data)>
</cfif>
</cfloop>

<cfdump var="#driverInfo#">

0 comments:

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Header image adapted from atomicjeep