Connecting to Database with JDBC
By Bruce Eckel
Approximately half of all software development involves client/server operations. A great promise of Java has been the ability to build platform-independent client/server database applications. Java DataBase Connectivity (JDBC) in Java 1.1 makes it possible to build client/server database applications that are platform independent. Although there is a "standard" database language, Structured Query Language (SQL-92), features wars have often made it necessary to write vendor-specific code. Because JDBC is designed to be platform independent, you needn't worry about which database you're using while programming; it is, however, possible to make vendor-specific calls.
Like many Java APIs, JDBC is designed for simplicity. Method calls correspond to logical database operations: connecting to the database, creating a statement and executing the query, and viewing the result set.
Opening a Database
To allow platform independence, JDBC provides a driver manager that dynamically maintains all the driver objects that database queries need. For example, connecting to three different kinds of vendor databases requires three different driver objects. The driver objects register themselves with the driver manager at load time, and you can force loading using Class.forName().
To open a database, you must specify the following information:
- That you're using JDBC.
- The "subprotocol," the name of either the driver or a database-connectivity mechanism.