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);
}

1 comment:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java EE Online Training from India . Nowadays Java has tons of job opportunities on various vertical industry.

    ReplyDelete