JDBC connection timeout
The Tutorial describe you a JDBC Connection timeout. In this program, we want to explain you a code that help you in understand the maximum time for which driver can wait to connect database.
Understand with Example
The code include a class JDBC Connection Timeout, inside the main method we include the list of following steps -
- The first step is to import a package name Java.sql.* - This package import the definition of all classes present in this package.
- Loading a driver -The next step is load a driver by calling class.forname( ) and passed the driver as argument in it.
- DriverManager.getLoginTimeout( ) -This method return the maximum time for the driver can wait while trying to connect a database.
- DriverManager.getconnection ( ) - This method attempt to connect a url and database.
- con.createstatement ( ) - This method is used to return an Sql object. Once a connection is built ,your application page can interact with backend database. A connection object is used further to send and execute SQL Statement to a backend database
- next( ) - This method return you the next successive element in series.
- execute query - This method is used to retrieve a record from a database using select queries in sql .
On the execution of code,the code attempt to establish a connection between url and database in 10 sec.Finally the println print the element from the database.
JdbcConnectionTimeout.java
|
Output
Connection Login Timeout : 10 First Name Last Name girish tewari mahendra singh komal singh yogesh pandey pinku tripathi deepak tripathi |