Saturday, October 25, 2008

Listing the loaded JDBC drivers

package jdbctest;
import java.sql.*;

import java.util.Enumeration;

public class TestConnection {
public TestConnection() {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("Oracle JDBC driver loaded ok.");

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

System.out.println("Oracle JDBC driver loaded ok.");
DatabaseMetaData dm = conn.getMetaData();
System.out.println("Major Version= " + dm.getDatabaseMajorVersion() +
" Minor Version= " + dm.getDatabaseMinorVersion() +
" Product Name= " + dm.getDatabaseProductName());

System.out.println("Listing the Loaded drivers!");
listDrivers();

conn.close();

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

void listDrivers()
{
Enumeration eld = DriverManager.getDrivers();
while(eld.hasMoreElements())
{
Driver d = (Driver)eld. nextElement();
System.out.println(" Driver class: " + d.getClass().getName());
}
}

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

}
}

Output
Oracle JDBC driver loaded ok.
Major Version= 10 Minor Version= 2 Product Name= Oracle
Listing the Loaded drivers!
Driver class: oracle.jdbc.driver.OracleDriver

No comments: