What are the different types of driver?
- Type 1
JDBC-ODBC : by sun.com
- Type 2
Native API: partly Java Driver
- Type 3
Net Protocol: All Java Driver
- Type 4:
Native Protocol: Pure Java Driver
Which type of JDBC driver is the fastest one?
JDBC Net pure Java driver(Type IV) is the fastest driver because it converts the jdbc calls to network protocol used by DBMS Server.
Driver converts JDBC API calls to direct network calls using vendor specific networking protocols.
What are the different approaches that Java application can use to connect to a database via the driver? Explain them
JDBC-ODBC Bridge
Part Java, Part Native Driver
Intermediate database access server
Pure Java Drivers
1.
JDBC-ODBC Bridge The translation of JDBC calls into ODBC calls and sending to the ODBC driver is done by this driver. These drivers are almost accessible to any database. These drivers are not portable. The client system demands the ODBC installation to use the driver.
2.
Part Java, Part Native DriverThis driver translates the JDBC calls into a database-specific calls. This driver is database dependent. The communication layers in this drivers is less compared to type 1 driver and uses the database native api.
3.
Intermediate database access serverThe requests for the database using this driver passes to the middle-tier server through network. The middle-tier translates the requests to the database once the requests are passed to it. The presence of the vendor based library on the client system is not needed as it is server-based. This driver is portable and can be used for web applications. Data from multiple databases can be accessed by using this driver.
4.
Pure Java DriversThis driver uses the networking libraries of java in order to communicate directly with the database servers. These drivers were developed in java, so that they are portable, platform independent and deployment issues are eliminated. This driver is suitable for web applications. Installation of special softwares is not necessary and there drives can be downloaded dynamically. These drivers are vendor specific.
Explain how to load a database driver using JDBC.
The database drivers are to be loaded by Java Virtual Machine class loader. By using Class.forName() method, the driver class is loaded. The driver class is vendor and driver type specific. The vendors supplies the specific driver classes.
The following are the examples to load the vendor specific jdbc drivers. To load MySql driver : Class.forName("org.gjt.mm.mysql.Driver");
To load a DB2 driver: Class.forName (“com.ibm.db2.jdbc.app.DB2Driver”);
To load an Oracle driver: Class.forName(“oracle.jdbc.driver.OracleDriver”);
Explain the purpose of DriverManager.
DriverManager looks after the managing the drivers for a JDBC application. When it is instantiated it makes an attempt to load the driver classes. When the method getConnection() is invoked, the driver manager attempts to locate the suitable driver. The DriverManager obtains the information about the drivers such as registering, locating, finding the drivers loaded, setting the time to wait when it tries to get the connection to a database.