![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
![]()
(chat, newsreader, calendar)
|
![]() |
|
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.
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 2For 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 3For 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 4Close each statement.
Both the PreparedStatement and the Statement need to be closed
in their respective locations.
|
Copyright © 1997 MageLang Institute. All Rights Reserved May-97 Copyright © 1996, 1997 Sun Microsystems Inc. All Rights Reserved |