Friday, 8 October 2010

Showing your Microsoft SQL JDBC Driver Version

I wanted to find out which Microsoft MS SQL JDBC Driver I was using, without tearing open .jar files and reverse engineering stuff. Here's some Java Reflexion that does what I wanted.
try {
    Class cls = Class.forName("com.microsoft.sqlserver.jdbc.SQLJdbcVersion");
    Field fieldlist[] = cls.getDeclaredFields();
    for (Field fld: fieldlist) 
    {
        fld.setAccessible(true);
        out.append("<tr><td>" + fld.getName() + ":" + fld.getInt(cls)+ 
            "</td></tr>");
    }
}
catch (Throwable e) 
{
    log.error("problem getting sql driver version", e);
}

No comments:

Post a Comment