JDBC  «Prev  Next»

JDBC Statement - Exercise

Update an existing database using Statement objects

Objective: Update an existing database.

Exercise Scoring

This exercise is worth a total of 5 points. To receive full credit, you will need to place the Java code you added or changed in Example2 into the Student Response box. You should also include the output from your execution of the Example2 program. Once you have completed your answer, you will submit it.

Background and Overview

You have had some time to review the use of Statements and now it is time to gain experience using its executeUpdate() method. The purpose of this Example is to provide you the opportunity to demonstrate what you have learned about executing queries.
You will need to modify the Example2 program to add the following record to the HOSPITALS table.

10203,'Hospital e Materindad', 'Mata Grosso', 'Cuiaba',9.0

Download Files

The files for this exercise are contained in the JDBC Course Resource download.

Instructions

  1. Edit the Example2 program. Follow the form of the executeUpdate() method shown above and add the required change. The Example2 program marks the location for the change with the tag <<MODIFICATION 1>>. Also, be sure that the program uses the proper URL for your database. The URL must point to the directory location for the Cloudscape database.
  2. Modify the program to print a list of the hospital names in the database. This listing should include the new record you just added. The Example2 program contains the tag <<MODIFICATION 2>> to mark where to add these Statements. The Example2 program does not have template Statements for this second modification. You will have to copy or type in the correct Java code.
  3. Compile the project.
  4. Test the program and run it from the command line:
    c:\ JDBCCourse> java Example2
    

  5. Insert your executeUpdate() from the DatabasePortal class in the text box below.

Submitting our Exercise

Once you have entered your responses into the text boxes, click the Submit button to submit the exercise. Remember that you must submit all of your responses to this exercise at once.