Interact with the DatabaseADD / DISPLAY RECORD
SECTION: This section uses the utility method WwdUtils.getWishItem to
gather information from the User. It then utilizes the objects set up previously
to insert the data into the WISH_LIST table and then display
all records. A standard do loop causes the program to repeat
this series of steps until exit is entered. The data
related activities performed in this section are:The setString method
sets the substitution parameter of the psInsert object to
the value entered by the User. Then executeUpdate is called
to perform the database insert.psInsert.setString(1,answer);
psInsert.executeUpdate();
The statement object s is used to select
all the records in the WISH_LIST table and store them in
the ResultSet myWishes.myWishes = s.executeQuery("select ENTRY_DATE, WISH_ITEM
from WISH_LIST order by ENTRY_DATE");
The while loop reads each record in turn by calling
the next method. The getTimestamp and getString methods
return specific fields in the record in the proper format. The fields are
displayed using rudimentary formatting.while (myWishes.next())
{
System.out.println("On " + myWishes.getTimestamp(1) +
" I wished for " + myWishes.getString(2));
}Close the ResultSet to release the memory being used.myWishes.close();