Necessary step to work with JDBC
- Load the JDBC driver.
- Get the db connection via driver.
- Issue SQL query via connection.
- Process the result return by SQL query.
- Close all JDBC object and Connection.
JDBC is an API(Collection of Packages) and ituses Driver to interact with database
- Driver is additional software component require by JDBC to
interact with database.
- Driver are Provided by Database vendor and they are Database
- Driver is a concrete class present in jar file
- Driver help us to establish database connection, transfer database
query and result between java program and database.
How to load Driver
import java.sql.DriverManager; import com.mysql.jdbc.Driver; Driver ref=new Driver(); DriverManager.registerDriver(ref);
another way to load driver using Class.Forname, this approach is most common approach to load driver and itautomatically register Driver class.
Types of JDBC Driver:
- Type-1 JDBC ODBC Bridge
- Type-2 Native API
- Type-3 Network protocol
- Type-4 Native Protocol
- Type-1 and Type-2 require Client side installation so it is less efficient.
- Type-3 and Type-4 Driver develop using java so it is efficient.
- Type-3 driver support More database.
- Type-4 Driver give high performance because it is directly connected with database
- Download MySQL zip file and Extract it
- Go to eclipse IDE.
- Right click on project
- Select build path
- Choose option “Add External Archive” and Select mysql connector jar file.
- It is collection of ‘ .class ‘ + other necessary resources(text, XML etc).
- Jar file help us to transfer the java application from one place to another place.