JDBC  «Prev 

JDBC Batch Updates - Exercise

Using batch updates and Prepared Statements

Objective: Write code that prints information in a database.

Background/overview - Briefing Information



Download Files

The file used is Example4.java of the JDBCCourse download set (brazilproject.zip) and is available in the Resources section accessible through your course toolbar.

Instructions

  1. Edit the Example4.java program
  2. Locate the <<MODIFICATION 1>> tag in the program. The program is currently written using the execute() method to direct SQL commands to the database. Change the program to use the addBatch() and executeBatch() methods. Directions about where these changes should occur are in the program comments.
  3. Locate the <<MODIFICATION 2>> tag. Change the program so that it uses the appropriate method to create a PreparedStatement.
  4. Locate the <<MODIFCATION 3>> tag. Change the program so that it uses the correct method names for the type of data which is set in the prepared statement. The data type used in the method must match the type of the method's second argument. Also, set the correct parameter indexes as the first argument of these methods.
  5. Locate the <<MODIFICATION 4>> tag. Add methods to obtain the SQLState, ErrorCode, and Messages and print them out.
  6. Compile the program.
  7. Test the program by running it from the command line. (Don't forget to run the setJV102env.bat script first.)
  8. To review the database changes, start Cloudscape's administrative tool, Cloudview. Cloudview will allow you to view the rows in a Cloudscape database. Run startCloudview.bat to start Cloudview. Once it is running, open the BrazilProjects database, and you should see the new DOCTORS table. If you open the table, you should be able to see the rows your program added.