dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Java
Expertise: Intermediate
Jul 2, 2007

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


In-memory JDBC Driver Details

When you're working with JDBC, you can load more than one JDBC driver in memory. To find out how many drivers are in memory, along with other useful driver information, use the following code:

import java.sql.*;
import java.util.*;

public class drvinf{

public static void main(String[] args)
  {
  Connection conn=null;
  ResourceBundle bundle = ResourceBundle.getBundle("START");
  String drv=null;
  String url=null;

  //load a JDBC driver
  try{
     drv = bundle.getString("Driver");
     Class.forName(drv);
     }catch (ClassNotFoundException e)
       {System.out.println(e.getMessage());}

  //JDBC URL=jdbc:odbc:bank
  try{
     url = bundle.getString("jdbcURL");
     conn = DriverManager.getConnection(url);

     List drvs = Collections.list(DriverManager.getDrivers());
     for (int i=0; i<drvs.size(); i++)
       {
       System.out.println("---------------------------------");
       Driver driver = (Driver)drvs.get(i); 
       String name = driver.getClass().getName(); 
       System.out.println(name);
       int maxV = driver.getMajorVersion();
       System.out.println(maxV); 
       int minV = driver.getMinorVersion();
       System.out.println(minV); 
       boolean comp = driver.jdbcCompliant();
       System.out.println(comp); 
       }    
    }catch (SQLException e)
    {System.out.println(e.getMessage());}
       try{
          if(conn!=null)conn.close();
          }catch(SQLException e)    
               {System.out.println(e.getMessage());} 
    }
}
The START.properties file should look like this:

Driver=sun.jdbc.odbc.JdbcOdbcDriver
jdbcURL=jdbc:odbc:bank
login=admin
password=hashflush
Leonard Anghel
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date