Wednesday, October 29, 2008

Printing Database and Driver version using a simple JDBC program

Here is a simple JDBC program to print the version of your Database and the version of the JDBC driver.

package jdbctest;
import java.sql.*;

public class TestConnection {
public TestConnection() {
try {

Driver d = (Driver)Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
DriverManager.registerDriver(d);
System.out.println("Oracle JDBC driver loaded.");

Connection conn = DriverManager.getConnection("jdbc:oracle:thin:cric/buzz@testsvr:1521:orcl");
DatabaseMetaData dmd = conn.getMetaData();

System.out.println("Database Major Version: " + dmd.getDatabaseMajorVersion() + " Database Minor Version: " + dmd.getDatabaseMinorVersion());
System.out.println("Driver Major version: " + dmd.getDriverMajorVersion() + " Driver Minor Version : " + dmd.getDriverMinorVersion());

conn.close();

}
catch(Exception e) {
System.out.println("Exception"+ e);
}
}

public static void main(String[] args) {
TestConnection t = new TestConnection();

}
}
Output
Oracle JDBC driver loaded.
Database Major Version: 10 Database Minor Version: 2
Driver Major version: 11 Driver Minor Version : 1

No comments: