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: Command-Line Guestbook
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

Copy the odbc.datasource file from the previous exercise. And setup the Connection to the DriverManager.

import java.sql.*;

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

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

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

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

Task 2

For update mode, use a PreparedStatement to accept groups of three parameters from the command line to insert a comment into the table.

Use Connection.prepareStatement to do this.

Use PreparedStatement.setString to place each parameter.

Remember that arguments to prepared statements, start at 1, not 0.

Use executeUpdate, because the SQL statement to execute will update the database.

Task 3

For query mode, you can use a regular Statement. Remember to use findColumn to determine which column is for which field.

Use Connection.createStatement to do this.

Use Statement.executeQuery to send the SQL SELECT statement. The results will come back as a ResultSet.

Task 4

Close each statement.

Both the PreparedStatement and the Statement need to be closed in their respective locations.

Task 5

Close the connection.



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