Java Database Connectivity Drivers
|
Java Database Connectivity
|
|
•
|
Java Database Connectivity [JDBC] is the Java method for implementing database independent and platform independent database connectivity. Java defines a programming interface for interacting with an SQL database. Database vendors provide Java objects (usually in the form of a .jar file) that implement the programming interface on top of their databases. The collection of these objects is referred to as a Driver. These drivers are loaded by Java and then connections to the database can be made.
|
•
|
The Database package is built on top of JDBC; therefore to use Database, a JDBC driver must be available. Most database vendors provide JDBC drivers by either shipping them with the database software or providing downloads from their Web site. If vendor-supplied JDBC Drivers are unavailable (or are poorly implemented) there are third party JDBC drivers available as well (both commercial and otherwise).
|
•
|
Before trying to run Database, you must know three pieces of information about the JDBC Driver.
|
1.
|
The location of the JDBC Driver (usually in the form of a .jar file). This needs be specified in the call to LoadDriver or added to the CLASSPATH environment variable. This is required so the Driver can be loaded.
|
2.
|
The fully qualified package name of the Driver class (for example, com.mysql.jdbc3.Driver or org.postgresql.Driver). This is generally available in the JDBC Driver's documentation. Database does know some common JDBC Driver names; however, if it does not know the particular Driver in use or in case of conflict between installed drivers, this can be passed into LoadDriver.
|
3.
|
The URL used to specify a database connection. This is used by OpenConnection. The URL must be of the form "jdbc:subprot:dblocation". subprot is a JDBC Driver specific sub-protocol and dblocation specifies the location of the database. The correct format for subprot and dblocation depends on the JDBC Driver, and is generally available in its documentation.
|
|
For a list of known issues and workarounds for various databases and JDBC drivers, see the issues page.
|
|
|
Examples
|
|
Load a JDBC driver by specifying the driver and classpath.
>
|
|
Open a different driver.
>
|
|
Open a connection using the first driver. Notice the sub-protocol name and database location.
>
|
|
Open another connection using the second driver.
>
|
|
|
|
Download Help Document
Was this information helpful?