Java Reference
In-Depth Information
Q: What if I don't know any SQL?
A: That's no problem. If you have made it this far in the topic, you are
clearly someone who understands languages. I can show you
enough SQL to have you writing database programs within the
hour. Just check out the section An SQL Primer in this chapter and
carefully study the sample programs throughout this chapter.
Now that we have discussed how JDBC works, let's look at the important
topic of JDBC drivers. I will then show you how to select a driver in your Java
program, and connect to a database.
JDBC Drivers
To connect to a database and access its contents, you need a JDBC driver that
works with that particular database. There are many different JDBC drivers
available, and Sun keeps an updated, searchable list of them on their Web site at:
http://industry.java.sun.com/products/jdbc/drivers
JDBC drivers fit into four categories referred to as types , denoted simply by
the numbers 1 through 4. The four types of drivers are:
type 1 driver. A bridge driver , which allows JDBC to communicate with
any database that uses ODBC. When Java first came out, this was a
useful driver because most databases only supported ODBC access.
Nowadays, however, the bridge driver is not recommended beyond
testing purposes. The J2SE comes with a bridge driver that we will use
in the examples in this chapter.
type 2 driver. A native API driver , meaning that the driver converts JDBC
calls into native API calls unique to the database. Type 2 drivers are
typically provided by the database vendor and require native code to
be deployed to any client using a type 2 driver.
type 3 driver. A JDBC-Net driver , which converts JDBC calls into a
database-independent net protocol, which is then translated into the
database-specific calls. A type 3 driver has advantages because it does
not require anything of the client, and the same driver can be used for
multiple databases. The conversions are made by using a middleware
application. Third-party vendors typically provide type 3 drivers.
type 4 driver. A native protocol driver, meaning that JDBC calls are
converted directly into native calls to the database. They are pure-Java
drivers that do not require native code on the client side. The JDBC
drivers provided by the database vendor are typically type 4 drivers.
Search WWH ::




Custom Search