A truly useful servlet application is to add database connectivity. Adding a database to a servlet is no different from adding a database to an applet or application. Servlets basically can access variety of data sources such as relational databases, directory servers , proprietary file formats ,XML formats etc. We can use any sort of database connectivity provided JDBC connectivity is done through appropriate JDBC driver.
JDBC driver
JDBC driver is what the JVM uses to translate the generalized JDBC calls in to Vendor-specific database calls that the database will understand. These drivers are java classes that are loaded at runtime.
Java soft has classified drivers into four types which deployed appropriately works will all types databases. They are
JDBC-ODBC bridge/Type 1 driver
This tier translates standard JDBC calls to corresponding ODBC call and sends it to an ODBC data source through the operating system’s ODBC libraries where the request is processed and the results are send back
Native-API partly Java driver/Type 2 driver
This driver is similar to Type1 except Translation layer. when a database call is made using JDBC the driver will translate the code into something that vendor API will understand .the database then processes and sends back the results through API.
JDBC-Net pure Java driver/ Type3 driver
Uses java driver and all java middle tier to provide data access to your programs. A JDBC call is send to middle tier without translation through JDBC driver then middle tier uses Type 1 or Type 2 driver to talk to the database.
Native-Protocol pure Java driver/Type 4 driver
Type 4 driver is an alljava driver that issues requests directly to the database. This is considered to be the most efficient method of accessing your database.
JDBC API
The JDBC API is made of Classes and Interfaces in java.sql and java.text packages. Within these packages you will find a set of method that allows you to connect to the database , retrieve information in the database and perform SQL queries and execute stored procedures.
|