![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
![]()
(chat, newsreader, calendar)
|
![]() |
|
Course Notes Table of Contents | Exercises JDBC Short Course Index | Online Training Index
|
Help: Connecting without JDBCTest |
Working Applet | Help Solution
|
Help is available for each task, or you can go straight to the
source code, which is one particular
solution.
Before you can connect to the database, register the JDBC driver. As in the previous example, you are going to use the JDBC-ODBC bridge provided with the JDK. The registration process involves loading the class. In this case, the driver name is the sun.jdbc.odbc.JdbcOdbcDriver class. Use Class.forName to load it, and check for exceptions. The class must be locatable in the CLASSPATH. This should not be a problem because this driver is part of the JDK distribution.
Once you have the driver registered, you can use it to connect to the database. This is done through the DriverManager.getConnection method. The getConnection method requires three parameters, similar to the 'Select A Database' window before: the URL, username, and password. As a result, it creates an instance of Connection.
The URL begins with jdbc:odbc. If you setup your datasource
according to the Getting Started exercise, the
URL is jdbc:odbc:mage.
To truly duplicate JDBCTest, once you have the database metadata, print out all the information available. As a cautionary note, not all existing JDBC drivers provide database metadata. The Imaginary mSQL driver does not. If you are using an incomplete JDBC driver, check for null before examining the database metadata.
You might want to print one or two of the items that interest you.
Instead of printing everything you can just find a few things you are interested in and print them out.
|
Copyright © 1997 MageLang Institute. All Rights Reserved May-97 Copyright © 1996, 1997 Sun Microsystems Inc. All Rights Reserved |