A JDBC Driver Is A Software Component Enabling A Java Application To Interact With A Database
A JDBC Driver Is A Software Component Enabling A Java Application To Interact With A Database
[1] JDBC drivers are analogous to ODBC drivers, ADO.NET data providers, and OLE DB providers. To connect with individual databases, JDBC (the Java Database Connectivity API) requires drivers for each database. The JDBC driver gives out the connection to the database and implements the protocol for transferring the query and result between client and database.
Translates query obtained by JDBC into corresponding ODBC query, which is then handled by the ODBC driver. Sun provides a JDBC-ODBC Bridge driver. sun.jdbc.odbc.JdbcOdbcDriver. This driver is native code and not Java, and is closed source. Client -> JDBC Driver -> ODBC Driver -> Database
Advantages
Disadvantages
Performance overhead since the calls have to go through the jdbc Overhead bridge to the ODBC driver, then to the native db connectivity interface. The ODBC driver needs to be installed on the client machine. Considering the client-side software needed, this is not suitable for applets. Compared to other driver types it's slow.
The Sun driver has a known issue with character encodings and Microsoft Access databases. Microsoft Access may use an encoding that is not correctly translated by the driver, leading to the replacement in strings of, for example, accented characters by question marks. One workaround is to avoid reading strings directly, but rather to read the raw bytes and then translate these into a string, specifying the correct source encoding:
The vendor client library needs to be installed on the client machine. Not all databases have a client side library This driver is platform dependent This driver supports all java applications except Applets
Can interface to multiple databases - Not vendor specific. The JDBC Client driver written in java, communicates with a middleware-netserver using a database independent protocol, and then this net server translates this request into database commands for that database. Thus the client driver to middleware communication is database independent. Client -> JDBC Driver -> Network-protocol driver -> Middleware-Net Server -> Any Database,...
[edit] Advantages
Since the communication between client and the middleware server is database independent, there is no need for the vendor db library on the client machine. Also the client to middleware need not be changed for a new database. The Middleware Server (which can be a full fledged J2EE Application server) can provide typical middleware services like caching (connections, query results, and so on), load balancing, logging, auditing etc. Eg. for the above include jdbc driver features in Weblogic. o Can be used in internet since there is no client side software needed. o At client side a single driver can handle any database. (It works provided the middleware supports that database!)
[edit] Disadvantages
Requires database-specific coding to be done in the middle tier. An extra layer added may result in a time-bottleneck. But typically this is overcome by providing efficient middleware services .
[edit] Functions
Type 4 drivers, coded entirely in Java, communicate directly with a vendor's database, usually through socket connections. No translation or middleware layers are required, improving performance. The driver converts JDBC calls into the vendor-specific database protocol so that client applications can communicate directly with the database server. Completely implemented in Java to achieve platform independence. This type includes (for example) the widely-used Oracle thin driver oracle.jdbc.driver.OracleDriver which connects using a format configuration of jdbc:oracle:thin:@URL Client -> Native-protocol JDBC Driver -> database server.
[edit] Advantages
These drivers don't translate the requests into an intermediary format (such as ODBC), nor do they need a middleware layer to service requests. This can enhance performance considerably. The JVM can manage all aspects of the application-to-database connection; this can facilitate debugging. Provides a way to manage copies of the database for each user.
Disadvantages
Connecting To Access
Example code to connect to Access type of database:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connecting To Oracle
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Class.forName("oracle.jdbc.driver.OracleDriver");
Jdbc-Odbc Bridge:may or may not need username, password Jdbc:Odbc:Dsn1 Jdbc:Odbc:Dsn2 Oracle : needs username, password jdbc:oracle:thin:@localhost:1521:orcl jdbc:oracle:oci DB2 : jdbc:db2:mySource Pointbase :