JDBC API: As part of Java 2 Standard Edition (J2SE), an API is provided to access the data managed by database servers like ORACLE, MySQL, Microsoft SQL Server, DB2, Sybase, etc. The name of the API is Java Database Connectivity (JDBC).

JDBC is a open specification i.e.; the specification is released as a public document and it is available for every one. As part of JDBC specification, Javasoft has provided various interfaces like java.sql.Driver, java.sql.Connection, java.sql.Statement, java.sql.PreparedStatement, java.sql.CallableStatement, java.sql.ResultSet etc.

Any company can provide a set of classes implementing the interfaces specified by Javasoft as part of JDBC API. These classes combined together is called as JDBC driver.

Oralce's JDBC driver is a set of classes that implements JDBC interfaces and the code in these classes is provided to deal with Oracle. For a single databse server, there can be multiple JDBC drivers avaialbe in market. The vendors of JDBC drivers suply the classes as part of JAR file. Oracle corp. provides ojdc14.jar

In order to use a JDBC driver, we must read the documentation provided by the JDBC driver vendor for the following information.
a. Name of the driver class. Eg: com.mysql.jdbc.Driver, oracle.jdbc.driver.OracleDriver
b. Format of the JDBC URL. Eg: jdbc:mysql://[domain or host]:[port]/[DB name], jdbc:oracle:thin:@[domain or host]:[port]:[DB name]

If the MySQL server and Java application are running on the same machine, then we can use localhost as a domain name in the above example JDBC URL.

Procedure for establishing the connection:
1. Register the driver using DriverManager.registerDriver() method as shown below
   DriverManager.registerDriver(new com.mysql.jdbc.Driver());
2. Establish the connection with the database server using DriverManager.getConnection as below
  Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3308/test", "root", "test");

import java.sql.*;

public class DBApp1
public static void main(String args[]) throws Exception
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3308/test", "root", "test");
System.out.println("Connection to DB..."+connection.getClass());
Instead of using DriverManager.registerDriver(new com.mysql.jdbc.Driver()), we can use Class.forName("com.mysql.jdbc.Driver"); for registering the driver. As part of the driver class, the JDBC driver implementer provides a static block to register the driver.

When the above Class.forName(...) is executed, the driver class will be loaded and the static block of the driver class will be executed this static block which will take care of registering the driver.

When DriverManager.getConnection(...) is executed, the code provided by the JDBC driver vendor will be executed. This code creates an object based on a class implements the Connection interface provided by the JDBC driver vendor.

More to follow... stay tuned...