SER322 Database Management Systems Lab: JDBC Programming and XML
SER322 Database Management Systems Lab: JDBC Programming and XML
This lab asks you to write simple JDBC programs, and execute an XPath query.
Example of output:
2. (7.5p) Write a method named query2 that uses JDBC to execute a SELECT query to List, for a provided
Language, the movies for that language (ID, Title, Release Date) together with the Number of actors that
act on each of them. Note if a movie has 0 actors, it should appear with a 0 (For example, film with id 5, in
Spanish, has not actors)
a.
Use a PreparedStatement with a parameter for the LanguageName and filter the query results to
only return rows tied to that Language.
b. Pretty-print the results to the console (One line per row in readable aligned columns)
c. This would be invoked on the command line as
java ser322.JdbcLab <url> <user> <pwd> <driver> query2 <language_name>
3. (7.5p) Write a method named updateFilm that uses JDBC to update the length of a Film in the database
a. Use a PreparedStatement with parameter for the value to UPDATE
b. Be sure to commit your results appropriately!
c. If successful, indicate by printing out SUCCESS
d. This would be invoked on the command line as
java ser322.JdbcLab <url> <user> <pwd> <driver> updateFilm
<film_id> <new_length>
Note: you can run query1 to check on updateFilm, as the results should change.
4. (7.5p) Write a method named addActor that uses JDBC to add an existing actor to a movie providing the
actor_id and the film_id
a. Use a PreparedStatement with parameters for the 2 values to INSERT
b. Be sure to commit your results appropriately!
c. If successful, indicate by printing out SUCCESS
d. It should display a nice error message if an actor is already in a movie.
e. This would be invoked on the command line as
java ser322.JdbcLab <url> <user> <pwd> <driver> addActor
<actor_id> <film_id>
Note: you can run query2 to check on addActor, as the results should change if there is a new actor in the
movie!
Submission Instructions:
You should submit a zipfile with the following contents:
o A readme.txt that explains how to build the source code. Given these are small standalone
programs, a simple javac command is fine.