|
Training Index
Help - Applet-Based Guestbook
by Magelang Institute
[Table of Contents]
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.
Task 2
Each connection to the CommentsServer creates an instance of CommentsConnection.
It is your job to fill in the run method for this Thread.
First determine which command came across. Valid commands are query and
insert.
Use something like s.equals ("insert") as the if condition to check
for the insert command.
Task 3
For insert mode:
- Read the name, username, and comments from the
ObjectInputStream.
- Setup the
Connection to the DriverManager.
- Create a statement.
- Populate/execute it.
Use ObjectInputStream.readObject() to read the strings from
the socket's InputStream.
Ask the CommentsServer for the URL, username, and the password to use when
getting your connection from the DriverManager.
Use Connection.prepareStatement to create a statement.
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 4
For query mode:
- Setup the
Connection to the DriverManager.
- Create a statement.
- Execute it.
- Read in
ResultSet.
Ask the CommentsServer for the URL, username, and the password to use when
getting your connection from the DriverManager.
Use Connection.createStatement to create statement.
Remember to use findColumn to determine which column is for which field when examining the ResultSet.
Task 5
Close each statement.
Both the PreparedStatement and the Statement need to be closed
in their respective locations.
Task 6
Close the connection.
Copyright © 1996 Magelang Institute. All Rights Reserved.
|