Analytics


Google

Wednesday, October 17, 2012

Retrieving JDBC version information

The following is how you can retrieve the jdbc version:


import oracle.jdbc.OracleConnection;
import oracle.jdbc.pool.OracleDataSource;
import java.sql.SQLException;
import java.sql.DatabaseMetaData;
import java.util.Properties;
 
 
public class JDBCVersionInfo {
   
  public static void main(String[] args) {
    try {
      // Set up user connection properties
      Properties prop = new Properties();
      prop.setProperty("user","hr");
      prop.setProperty("password","password");
       
      // open the connection
      OracleDataSource ods = new OracleDataSource();
      ods.setConnectionProperties(prop);
      ods.setURL("jdbc:oracle:thin:@//prod:1521/proddb");
      OracleConnection ocon = (OracleConnection)ods.getConnection();
       
      DatabaseMetaData dbmd = ocon.getMetaData();
       
      System.out.println("Driver Name: " + dbmd.getDriverName());
      System.out.println("Driver Version: " + dbmd.getDriverVersion());
     
       
    } catch(SQLException e) {
      System.out.println(e.getMessage());
    }
  }
}
 
Reference from the following url:
 

No comments: