Ads 468x60px

Monday, July 25, 2011

Building a JDBC Implementation | JAVA


Building a JDBC Implementation

Building a JDBC implementation requires a lot more in-depth knowledge of both your DBMS and the JDBC specification than does simply coding to it. Most people will never encounter the need to roll their own implementation because database vendors logically want to make them available for their product. Understanding the inner workings of JDBC can help advance your application programming, however.
JDBC is a low-level interface that provides direct SQL-level access to the database. Most business applications and class libraries abstract from that SQL-level access to provide such features as object persistence and business-aware database access. A narrow example of such an abstraction is the Database class from the counter example.
The ideal object method of accomplishing these goals is to reuse existing JDBC implementations for the DBMS in question and to add custom interfaces on top of those implementations. If the DBMS is an oddball DBMS, or perhaps if you are concerned about the available implementations that exist, writing one from scratch makes sense.

Implementing the Interfaces

The first concern of any JDBC implementation is how it will talk to the database. Figure 15.3 illustrates the architecture of three possible JDBC implementations. Depending on the design goals in question, one of these methods will suit any JDBC implementation:


  • A native C library
  • A socket interface
  • Extending a vendor JDBC implementation
Of course, extending a vendor JDBC implementation is not really the same as building a JDBC implementation. Because a key to any object-oriented project is reusing code instead of building from scratch it is listed here.
With all three architectures, the application is apparently isolated from the actual communication mechanism. In truth, however, the native C library method places severe restrictions on any application using a JDBC implementation built on top of it. Because it uses native calls, it is naturally not portable across operating systems. In addition, due to virtual machine restrictions on most browsers, native calls are either severely limited or fully restricted.
To use one of these mechanisms for database communication, you need to construct the four basic interfaces: java.sql.Driver, java.sql.Connection, java.sql.Statement, and java.sql.ResultSet. These interfaces will provide minimum functionality so that you can test against simple queries and updates. Once these interfaces are functional, the implementation needs the meta-data interfaces as well as the Statement subclasses to be complete and JDBC-compliant.

0 comments:

Post a Comment