JDBC System Basics - JDBC - A developing program for Java
What is JDBC?
JDBC stands for the Java database connectivity protocol. Based on the same X/Open CLI standard as Microsoft's object database connectivity protocol, the JDBC applications programmable interface (API) is designed to allow developers to access databases within programs that are written in Javasoft's Java programming language, using structured query language (SQL).
JDBC was developed this year by Javasoft and a group of vendors, including Intersolv, and the current release is JDBC v1.01.
Written to define database connections, results sets, database metadata and other database-related queries and responses for the Java language, it ships as a set of object classes and documentation, providing an easy-to-access gateway between Java programs and SQL.
JDBC has two main advantages. First, it is platform-independent because all Java programs run in a virtual computer which has been created in software on the host platform. Provided that there is a virtual computer written for your hardware you can run Java programs.
Second, because the program is independent and works by loading small executables in memory, called applets, it is ideal for use over the Internet.
As a Java API, JDBC is a protocol that is well suited for accessing databases over the Internet, or from environments where different client platforms are used.
What are the other Java enterprise APIs?
JDBC is only one of a set of APIs designed to allow developers to run Java programs efficiently across the enterprise, rather than simply as applets on the desktop.
Another is Java IDL, an API that allows developers to connect Java programs into the common object request broker architecture (CORBA), which is the object management group's protocol enabling many different companies' object-oriented frameworks to interoperate. Interface definition language (IDL) is the foundation on which CORBA is based.
There is another API, called Java remote method invocations (JRMI), which allows different virtual machines to call procedures from each other.
Javasoft also produces JOE, which is an API that sits on top of Java IDL and includes all the application development tools to allow programmers to access Sun's CORBA-compliant NEO object framework.
While the Java IDL and RMI APIs are included in the Java development kit (JDK) available from Javasoft, JOE is not. This is because it is written directly with Sun-specific software in mind, rather than strictly to the Java standard alone.
How does it fit in with ODBC?
The open database connectivity (ODBC) is Microsoft's protocol that allows its object-oriented front ends to hook directly into databases using SQL.
The main difference between ODBC and JDBC is that the latter has been designed purely with Java programs in mind. While JDBC accesses databases using object classes, ODBC is based on accesses written in C. C-coded procedures will access databases even if the front end is written in another language, such as 4GLs. Embedding chunks of C code in a Java program affects its portability, defeating Java's main purpose.
The rule is that ODBC is for other front ends (particularly Microsoft-based ones), while JDBC is only for Java front ends.
Should I stop using CGI?
The common gateway interface (CGI) is a way of accessing C-based programs from Web-based front ends. As such, it can be used for accessing back-end databases over the Web. CGI will be around for a considerable time because it is a tried and tested technology, but it has some non-trivial problems.
CGI accesses tend to be mainly made up of ASCII, meaning that they are large. This can be irritating enough on Lans but when trying to access servers over narrow Internet communications links it can be debilitating.
What does JDBC work with?
There are four main types of driver for the JDBC protocol.
The JDBC-ODBC bridge converts JDBC access directly to ODBC-based queries.
The second converts JDBC calls to client API calls for many of the most popular databases. The third type converts JDBC calls to a database engine-independent protocol, which is subsequently translated to queries for specific database engines by a server.
The fourth engine, the native-protocol all-Java driver, converts JDBC calls directly into the network protocols used by the database engines.
JDBC works with most databases because many vendors have JDBC-ODBC bridge drivers - and many databases support ODBC. Native JDBC drivers are rarer and only two (from Borland and Imaginary) are currently available.
Is it expensive?
Quite the contrary. Javasoft wants the Java standard to take off and consequently copies of JDBC are available free. You can download it from the Javasoft Web page at http://java.sun. com/products/index.html.