In this Tutorial we want to describe you a code that helps you in understanding JDBC Connectivity Code in Java. In this program, the code returns you the time set by the driver to connect url and database. For this we have a class JdbcConnectivityCodeInJava and include the main method given by the list of steps are involved -
In order to know the time required to connect url and database, we import a package java.sql,enables you to connect the url and database. Loading a driver by calling a class.forName ( ),that accept driver class as argument. Once the driver is loaded, you set the time by the driver to connect url and database. The following methods are used to set and get the time by driver -DriverManager.setLoginTimeout ( ) - This method set you the time taken by the driver to connect the url and a database in second.
DriverManager.getLoginTimeout( ) -This method return the time taken by the driver to connect the url and a database in second.
On execution of the code connection login timeout is printed and connection is created.. In case there is an exception occurred in establishing a connection between database and url in the try block. The catch block check the exception and println print the exception.
Connection Login Timeout : 10 Sec Connection is created....
Posted on: November 17, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles