The code sample below calculates the time it takes to connect to a database referred by dsn.

Java Code:
long connection_time; 
Date start = new Date();  //get start time
String stUrl_= "jdbc:odbc:myDSN"; 
connection_ = DriverManager.getConnection(stUrl,"sa","sa");
Date end = new java.util.Date();  //get end time
connection_time = end.getTime()-start.getTime();