Java Reference
In-Depth Information
Note
Java 7 supports JDBC 4.1. For a list of JDBC 4.1-specific features, check
Data Sources, Drivers, and Connections
AlthoughJDBCistypicallyusedtocommunicatewithRDBMSes,italsocanbeusedto
communicatewithaflatfiledatabase.Forthisreason,JDBCusestheterm
data source
(adata-storagefacilityrangingfromasimplefiletoacomplexrelationaldatabaseman-
aged by an RDBMS) to abstract the source of data.
isaccessedviamethodsofthe
java.io.RandomAccessFile
class,whereasJava
DBdatabasesareaccessedviaSQLstatements),JDBCuses
drivers
(classfileplug-ins)
toabstractovertheirimplementations.Thisabstractionletsyouwriteanapplicationthat
canbeadaptedtoanarbitrarydatasourcewithouthavingtochangeasinglelineofcode
(in most cases). Drivers are implementations of the
java.sql.Driver
interface.
JDBC recognizes four types of drivers:
•
Type 1 drivers
implement JDBC as a mapping to another data-access API
(e.g., Open Database Connectivity, or ODBC—see
ht-
tp://en.wikipedia.org/wiki/ODBC
)
. The driver converts JDBC
methodcallsintofunctioncallsontheotherlibrary.TheJDBC-ODBCBridge
DriverisanexampleandisnotsupportedbyOracle.Itwascommonlyusedin
the early days of JDBC when other kinds of drivers were uncommon.
•
Type 2 drivers
arewrittenpartlyinJavaandpartlyinnativecode(seeAppendix
C). They interact with a data source-specific native client library and are not
portableforthisreason.Oracle'sOCI(OracleCallInterface)client-sidedriver
is an example.
•
Type 3 drivers
don'tdependonnativecodeandcommunicatewitha
middleware
server
(aserverthatsitsbetweentheapplicationclientandthedatasource)via
an RDBMS-independent protocol. The middleware server then communicates
the client's requests to the data source.
•
Type 4 drivers
don'tdependonnativecodeandimplementthenetworkprotocol
foraspecificdatasource.Theclientconnectsdirectlytothedatasourceinstead
of going through a middleware server.