Steps for creating connection with the database -


Step 1- Load the Driver

The first step to create connection with database is to load the specific driver class in the application environment so that it will be available when we need it for opening the connection.
The easiest way to load the driver is to use static method forName() provided by a class named Class. It has the following syntax -

static Class <?> forName(String Driver_Class_Name) throws ClassNotFoundException
Here Class is a predefined class that contains a static method forName(). The method takes a string parameter that should be the driver class name for specific database that you want to use. This method can throw a ClassNotFoundException, if driver class not found in execution path.

Example -

try
{ 
Class.forName("Driver_Class_Name");
}
catch(ClassNotFoundException ex)
{
System.out.println("Driver Class is not loaded");
}
Different RDBMS makes use of different driver classes some of them are as follows -
1- for MySql -
Class.forName("com.mysql.jdbc.Driver");
2- for Oracle -
Class.forName("oracle.jdbc.driver.OracleDriver");
3- for IBM DB2 -
Class.forName("com.ibm.db2.jcc.DB2Driver");