Technical Support
Discussion Forum
Online Training
Read About Java
Java In-Depth
Product Discounts
Membership Information JDC Resources DukeDollars

Java Cup Logo

JDC Home Page

JDC Applets
(chat, newsreader, calendar)

Log Out

Online Training
shadowSearchFAQFeedback

Course Notes Table of Contents | Exercises
JDBC Short Course Index | Online Training Index

Help: Connecting with Properties
Working Applet | Help
Solution

Help is available for each task, or you can go straight to the source code, which is one particular solution.

Task 1

Setup the file odbc.datasource in the current directory to have three key-value resources. (key=value)
KeyValue
datasource.namecontains the name of the ODBC datasource
datasource.usernamecontains the username to access datasource
datasource.passwordcontains the password of odbc.username

Use those setup in Getting Started.

Task 2

Import the JDBC package.

import java.sql.*;

Task 3

Load the sun.jdbc.odbc.JdbcOdbcDriver class.

Use Class.forName to load it, and check for exceptions.

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Task 4

Create a Connection to the DriverManager.

Use the resources read in from odbc.datasource resource file.

Connection con = DriverManager.getConnection(url, username, password);

Task 5

Examine the database metadata to display the name and version of the database and driver.

Use Connection.getMetaData to access this.

Task 6

Close the connection.



Copyright © 1997 MageLang Institute. All Rights Reserved
May-97 Copyright © 1996, 1997 Sun Microsystems Inc. All Rights Reserved