How to Use JDBC to Access SQL Data - dummies

How to Use JDBC to Access SQL Data

By Allen G. Taylor

JDBC (Java DataBase Connectivity) can be used with SQL to access data. JDBA is similar to ODBC, but it differs in a few important respects. One such difference is hinted at by its name. JDBC is a database interface that always looks the same to the client program — regardless of what data source is sitting on the server (back end).

The difference is that JDBC expects the client application to be written in the Java language rather than another language such as C++ or Visual Basic. Another difference is that Java and JDBC were both specifically designed to run on the web or on an intranet.

Java is a C++-like language that was developed by Sun Microsystems for the development of web-client programs. When a connection is established between a server and a client over the web, the appropriate Java applet is downloaded to the client, where the applet commences to run. The applet, which is embedded in an HTML page, provides the database-specific functionality that the client needs to provide flexible access to server data.


An applet is a small application that resides on a server. When a client connects to that server over the web, the applet is downloaded and starts running in the client computer. Java applets are specially designed so they can run in a sandbox — a well-defined (and isolated) area in the client computer’s memory set aside for running applets.

The applet is not allowed to affect anything outside the sandbox. This architecture is designed to protect the client machine from potentially hostile applets that may try to extract sensitive information or cause malicious damage.

A major advantage to using Java applets is that they’re always up to date. Because the applets are downloaded from the server every time they’re used (as opposed to being retained on the client), the client is always guaranteed to have the latest version whenever it runs a Java applet.

If you’re responsible for maintaining your organization’s server, you never have to worry about losing compatibility with some of your clients when you upgrade the server software. Just make sure that your downloadable Java applet is compatible with the new server configuration — because, as long as their web browsers have been configured to enable Java applets, all your clients automatically become compatible too.

Java is a full-featured programming language, and it is entirely possible to write robust applications with Java that can access databases in some kind of client/server system. When used this way, a Java application that accesses a database via JDBC is similar to a C++ application that accesses a database via ODBC. But a Java application acts quite different from a C++ application when it comes to the Internet.

When the system that you’re interested in is on the Net, the operating conditions are different from the conditions in a client/server system. The client side of an application that operates over the Internet is a browser, with minimal computational capabilities. These capabilities must be augmented in order for significant database processing to be done; Java applets provide these capabilities.

You face a certain amount of danger when you download anything from a server that you don’t know to be trustworthy. If you download a Java applet, that danger is greatly reduced but not completely eliminated. Be wary about letting executable code enter your machine from a questionable server.

JDBC passes SQL statements from the front-end application (applet) running on the client to the data source on the back end. It also serves to pass result sets or error messages from the data source back to the application. The value of using JDBC is that the applet writer can write to the standard JDBC interface without needing to know or care what database is located at the back end.

JDBC performs whatever conversion is necessary for accurate two-way communication to take place. Although designed to work over the web, JDBC also works in client/server environments where an application written in Java communicates with a database back end through the JDBC interface.