|
[Exercise | API Docs | Short Course| Exercises] Help is available for each task. Task 1The application can use the ConnectU.properties file. Duane decides to set up two arrays, one containing "Mon" through "Sun", the other containing "Monday" through "Sunday" ( to match the old and load the new data, ) and use two prepared statements. This work is done for you. Your job is to set up a query String to select all columns for reporting purposes, and two update Strings for the prepared statements. One String will be used to update the new column ( LDOW ) with a corresponding value from the second array when the DOW column contains a value from the first array. The other String will be used to update the column Type from "JustJoe" to "Jus'Joe". Insert the following query String:
"SELECT * FROM JJJJData",
Insert the following for the first update String:
"UPDATE JJJJData SET LDOW = ? WHERE DOW = ?",
Insert the following for the second String:
"UPDATE JJJJData SET Type = ? WHERE Type = ?",
Task 2The program goes through the familiar steps of accessing the ResourceBundle and retrieving the driver name, databaseURL, userID and password; loading the driver, getting a Connection and creating a Statement. Your job: add the new column -- the SQL statement should look like this: ALTER TABLE JJJJData ADD COLUMN LDOW VARCHAR (9) -- and print that the column was successfully added.
stmt.executeUpdate( "ALTER TABLE JJJJData " +
"ADD COLUMN LDOW VARCHAR (9)" );
System.out.println(
"Column LDOW added to Table JJJJData.");
Task 3Prepare both PreparedStatements.
pstmt1 = con.prepareStatement( sUpdate1 );
pstmt2 = con.prepareStatement( sUpdate2 );
Task 4Now the LDOW column needs to be loaded. The program has two corresponding arrays, asDOW and asLDOW, set up and the int ndx defined for use as an array index. Your job: create a loop in which, for each element of the asDOW array, you set the first parameter of pstmt1 to the current index value of asLDOW and the second parameter to the current index value of asDOW ( the relevant portion of the UPDATE statement looks like SET LDOW = ? WHERE DOW = ? ) Next, perform the update and accumulate the number of rows updated for reporting, once the loop is done.
Task 5Now it is time to update the Type column if it contains "JustJoe". Set the first parameter of pstmt2 to "Jus'Joe" and the second parameter to "JustJoe" ( the relevant portion of the UPDATE statement looks like SET Type = ? WHERE Type = ? ) Next, perform the update, get and report the number of rows updated.
Task 6Get and report all columns for all rows of JJJJData, showing the new data.
Copyright 1996-2000 jGuru.com. All Rights Reserved. | |||||||||||||
|
| ||||||||||||