JDBC stands for “Java DataBase Connectivity”. It is an API (Application Programming Interface) which consists of a set of Java classes, interfaces and exceptions and a specification to which both JDBC driver vendors and JDBC developers (like you) adhere when developing applications. JDBC is a very popular data access standard. RDBMS (Relational Database Management Systems) or third-party vendors develop drivers which adhere to the JDBC specification. Other developers use these drivers to develop applications which access those databases e.g. you’ll use ConnectorJ JDBC driver to access MySQL database. Since the drivers adhered to JDBC specification, the JDBC application developers can replace one driver for their application with another better one without having to rewrite their application. If they had used some proprietary API provided by some RDBMS vendor, they will not have been able to change the driver and/or database without having to rewrite the complete application.
Steps Required to use JDBC
1.Install JDBC, and the JDBC-ODBC bridge. (They can be obtained at http://splash.javasoft.com/jdbc.)
Note: if you are using any version of the JDK past 1.1, both JDBC and the JDBC-ODBC bridge are included.
2. Make the changes to your Java CLASSPATH variable specified in the installation instructions for JDBC and JDBC-ODBC. (Again, no changes are needed to the CLASSPATH if you’re using any JDK past 1.1.)
Example path for those using JDK 1.1 and up:
Example path for Windows NT, using JDK 1.0.2 : (all one line)
<span style="color: #111111;"> .;%SystemRoot%\java\lib\classes.zip;%SystemRoot%\java\Jdbc\jdbc\classes\; </span>
You can always set the variables by placing a “SET CLASSPATH ” command in your autoexec.bat file. You can also temporarily set the CLASSPATH by typing “SET CLASSPATH <…>” at the command prompt in a DOS Window. This setting only applies to that particular DOS Window, and thus is less convenient to use. Changes in the autoexec.bat file don’t become effective until you restart the machine. Changing environmental variables in Windows NT/2000, however, does not require restarting the machine. However, on NT, setting any environment variable from the control panel has no effect on any open DOS windows, so open a new DOS window to see the effects of your CLASSPATH changes.
3. Install the Microsoft Desktop Database drivers on your web server. These may not be included in a normal Windows NT/2000 or 95/98 installation. Thus, you might need to do a custom installation. The drivers should be under some section of the installation dealing with ODBC. Also install anything that relates to enabling ODBC (if it isn’t already installed).
4. Create your database. (Using, say, MS Access.) Place a copy of it on the web server.
5. Register the database as an ODBC database. To do this, go into the Control Panel, open up “ODBC”, click “Add”, click “Microsoft Access Driver” (if you’re using an Access database), then type in the name of your database, and click “Select” to browse for your database. That’s all you should need to do.
User vs. System DSN’s:
Note that if you want your database to be available regardless of who is logged onto your machine, you must register the database as a “System DSN”. Click the appropriate tab on the ODBC control panel to add a System DSN. If your machine has only one user, a “User DSN” is fine, provided you remain logged on as that user.
6. Compile and run the sample program. The sample is called “SimpleSelect.java” and it is in the JDBC-ODBC directory.
To run the sample, start by editing the file by changing the name of the database to your database. The code you need to change looks like this: String url = “jdbc:odbc:MyDatabase.mdb”;
The “jdbc:odbc:” part indicates that you intend to use the JDBC-ODBC bridge to open the database called “MyDatabase.mdb”. Change the name of the database to the database you plan to use. The name of the database should exactly match the name you gave to the database when you registered it in step 5.
( Note : A good utility for working with Java programs is WinEdit, and it would be a good idea to install that for editing your Java files. I don’t know where to obtain it on the net, though you could probably find it by doing a net search. I also have access to a CD that has it. It is a shareware product. Look at zdnet.com for other good programming editors, if you aren’t already using a product like Cafe or Visual J++.)
You will also need to amend the sample query to an SQL query meaningful for your database. See the end of this document for a brief discussion of SQL.
Once you’ve amended the sample program, save it, and compile it with the command
Run it using
The sample program has a routine called “dispResultSet” which simply displays, on your terminal, all the rows in your database that satisfy the query. You should see the result of your query print out on the DOS console. You’re done!
Note: On Windows NT/2000, you can reset the CLASSPATH variable by opening the control panel, selecting “System”, and then clicking the the Environment tab. You can’t do this in windows ’95/’98. Also note: omitting “.” at the start of your path is a common mistake.