• Keine Ergebnisse gefunden

Relational Databases 1 Exercise Sheet 11: Application Programming 1 (until Thursday 26.01.2012)

N/A
N/A
Protected

Academic year: 2021

Aktie "Relational Databases 1 Exercise Sheet 11: Application Programming 1 (until Thursday 26.01.2012)"

Copied!
3
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Relational Databases 1

Exercise Sheet 11: Application Programming 1 (until Thursday 26.01.2012)

Please note that you need 50% of all exercise points to receive the “Studienleistung”. Exercises have to be turned in until Thursday of each respective week and must be completed in teams of two students each. You may hand in your solutions either on paper before the lecture or into the mailbox at the IFIS floor (Mühlenpfordtstraße 23, 2nd floor). Please do not forget your “Matrikel- nummer” and your tutorial group number on your solutions. Your solutions may be in German or English. Please note: To pass the “RDB 1 Modul” you need the exercise points and the exam!

Please hand in all SQL statements for your solutions on paper and via e-mail to your tutor.

General Information

This week, we will do some practical exercises in our DB2 database. For doing so, a full dump of the IMDB database is provided to you. You may access and query the database as described in the next section. The schema of the database is really a pretty bad one – don‟t be tempted to create such a schema yourself (we do not know how IMDB could ever end up with such a horrible schema; proba- bly they skipped their course on data modeling…). Furthermore, the schema does not contain any primary nor foreign keys. However, columns sharing the same name can safely be assumed to have the same semantics (e.g. actors can be associated with a movie via title_id).

Try to familiarize yourself as good as possible with the schema. IMDB uses Strings as IDs for the different tables. These Strings contain all information about a movie, like e.g. title or year. The differ- ent parts of the ID-String are already split up into single attributes in the tables. Please note, the IDs should only be used for table joins! For other tasks use the respective attributes!

Example:

title_id: Terminator 3: Rise of the Machines (2003) (VG) title_title: Terminator 3: Rise of the Machines title_year: 2003

title_type: video game

Setting up

First, you need to download the db2 driver from the IBM Website:

https://www-304.ibm.com/support/docview.wss?uid=swg24028317

The file you need is inside the downloaded archive (db2jcc4.jar).

For accessing the database, we still use the Netbeans IDE which needs to be configured as follows (if you prefer, feel free to use any other SQL client):

Register the downloaded driver with Netbeans as shown in Figure 1 and Figure 2.

(2)

Figure 1 Add new driver in Netbeans Figure 2 Add DB2 driver

Create a new database connection as shown in Figure 3 to Figure 5. Use the following JDBC connec- tion URL (don‟t forget the ; ):

jdbc:db2://dblab.ifis.cs.tu-bs.de:50000/dblab:retrieveMessagesFromServerOnGetMessage=true;

Figure 3 Create new connection Figure 4 Enter the properties Figure 5 Select IMDBRAW

Finally, select IMDB as default schema.

Everytime you start Netbeans, you have to connect to the database and execute the command SET SCHEMA IMDB (Figure 6 - Figure 8).

Figure 6 Connect Figure 7 Create new Com-

mand Figure 8 Execute set Schema

After that, you may start querying the DB and review results (Figure 9).

(3)

Figure 9 Execute Queries

Exercise 11.1 (14 points)

a)

Create a table movie in your own schema, including the attributes id, movie_type, title and movie_year and copy all movies from the IMDB.MOVIES table to your own table that were produced between 1995 and 2000 (including 1995 and 2000). (2 points)

b) How many different movie types are included in your table and how many movies are there for each type? (2 points)

c) Delete all movies from your table that are not of type „film‟ or „TV movie‟. (2 points)

d)

Create a table actors in your schema including all actors participating in the movies in your

movies table. The table should have the following columns: id, actor_name, movie_id, charac- ters and sex. The sex column should mark if an actor is „male‟ or „female‟. Please note, in the IMDB schema all male actors are in the actors table, and all female actors are in the actresses table. (3 points)

e) How many female and male actors are included in your table? (2 point) f) What is the title of the movie having the most female actors? (3 points)

Exercise 11.2 (8 points)

For the following queries you have to use the IMDB schema.

a) How many „Action‟ movies have been produced in the „USA‟. (2 points)

b) Show the top-100 countries that have produced the most „Action‟ movies. (2 points) c) Create a query showing the number of cinema movies (type=‟film‟) where Arnold Schwarze-

negger participated in. The query should also include the rank of Arnold Schwarzenegger re-

garding all other male actors and their number of cinema movies. (4 points)

Abbildung

Figure 1 Add new driver in Netbeans  Figure 2 Add DB2 driver
Figure 9 Execute Queries

Referenzen

ÄHNLICHE DOKUMENTE

Nucula nitidosa Ophelia borealis Paramphinome

Figure 1: Digestion profile of a fragment (690 base pairs) of the amplified coding region of the mitochondrial gene of subunit 2 of NADH dehydrogenase, using PCR-RFLP. A)..

Based on this relation schema, please provide statements returning following results in relational algebra, tuple relational calculus and domain relational calculus:.

Is the data contained in the view created in exercise 11.1a physically stored or calculated at query time.. How can you influence, if the data is stored

In the file src/main/Main.java the application will try to connect to a database and then it will attempt to create a MovieExplorer object with the obtained Connection..

f) Show a list of all people (name) that includes the number of movies they have participated in as an actor. Of course, the list should also include all people that have

The Movie relation includes an id, the movie title, the year of publication, the country where the movie was produced, its box-office takings, and a type (e.g. cinema or TV)..

Also, you are re- quired to comment sections of your program code (using Java comments) so that it is easy to un- derstand by others (in particular by your tutor).. If your code