CS562 Project #1 Assignment Date : October 11th, 2012 Due Date : October 28th, 2012 TA: Lee,...

13
Implementing a simple application with embedded SQLs CS562 Project #1 Assignment Date : October 11th, 2012 Due Date : October 28th, 2012 TA: Lee, Min-Joong

Transcript of CS562 Project #1 Assignment Date : October 11th, 2012 Due Date : October 28th, 2012 TA: Lee,...

Page 1: CS562 Project #1 Assignment Date : October 11th, 2012 Due Date : October 28th, 2012 TA: Lee, Min-Joong.

Implementing a simple ap-plication with embedded SQLs

CS562 Project #1

Assignment Date : October 11th, 2012Due Date : October 28th, 2012

TA: Lee, Min-Joong

Page 2: CS562 Project #1 Assignment Date : October 11th, 2012 Due Date : October 28th, 2012 TA: Lee, Min-Joong.

Interactive SQL

SQL queries which you can type in at the SQL prompt.

INTERACTIVE SQL is good for: defining database structure▪ Create database, tables ….

generating low-volume, ad hoc queries prototyping

Page 3: CS562 Project #1 Assignment Date : October 11th, 2012 Due Date : October 28th, 2012 TA: Lee, Min-Joong.

Embedded SQL

SQL is a ‘non-procedural’ language. INTERACTIVE SQL is not good for the more so-

phisticated applications. SQL can be embedded within procedural

programming languages(host language). Supports

highly customized applications background applications running without user

intervention database manipulation which exceeds the abili-

ties of simple SQL.

Page 4: CS562 Project #1 Assignment Date : October 11th, 2012 Due Date : October 28th, 2012 TA: Lee, Min-Joong.

HOW to embedding SQL?

USE ESQL - old school style! ESQL/c, ESQL/C++ , ESQL/COBOL ,… ESQL is precompiled by preprocessor.

Use APIs JDBC ADO.NET ODBC …

Page 5: CS562 Project #1 Assignment Date : October 11th, 2012 Due Date : October 28th, 2012 TA: Lee, Min-Joong.

Embedded SQL

For example, JDBC, java Get names of awards which ‘Winona Ryder ‘

won.…Statement stmt1 = conn.createStatement();Statement stmt2 = conn.createStatement();ResultSet rs1 = stmt1.executeQuery("select actorID from actor where actor name = ‘Winona Ryder ‘ “);while (rs1.next()) { name = rs1.getString(1);} rs1.close();rs1 = stmt1.executeQuery(“select awordID from actorAwarded where actorID = “ + name );while (rs1.next()) { ResultSet rs2 = stmt2.executeQuery(“select awordName from award where awardID = “+ rs.getInt(1) ); System.Out.Println(rs2.getString(1));} rs2.close();

Page 6: CS562 Project #1 Assignment Date : October 11th, 2012 Due Date : October 28th, 2012 TA: Lee, Min-Joong.

Queries

Translate given statements into SQLs and process the query using your application. Initial data input Insert award data Insert rating data Select statements Update statements Delete statements

Page 7: CS562 Project #1 Assignment Date : October 11th, 2012 Due Date : October 28th, 2012 TA: Lee, Min-Joong.

Initial data

MovieName Director Actor Role Genre Publish

erRelate date

Edward Scissorhands

Tim Burton

Johnny Depp

Main actor Fantasy,Ro-mance

20th Century Fox Presents

1991.06.29

Winona Ryder

Main actor

Alice In Wonderland

Tim Burton

Johnny Depp

Main actor Fantasy,Adventure,Family

Korea Sony Pictures

2010.03.04

Anne Hathaway

Main actor

The Social Network

David Fincher

Jesse Eisenberg

Main actor Drama Korea Sony Pictures

2010.11.18

Andrew Garfield

Supporting Actor

The Dark Knight

Christopher Nolan

Christian Bale

Main actor Action,Drama

Warner Brothers Korea

2008.08.06

Heath Ledger

Main actor Mystery,Thriller

ActorName Date of

birthDate of death

Gender

Johnny Depp 1963.6.9   MaleWinona Ryder 1971.10.

29  Female

Anne Hathaway

1982.11.12

  Female

Christian Bale 1974.1.30

  Male

Heath Ledger 1979.4.4 2008.1.22

Male

Jesse Eisenberg

1983.10.5

  Male

Andrew Garfield

1983.8.20

  Male

CustomerName Date of birth GenderBob 1997.11.14 MaleJohn 1978.01.23 MaleJack 1980.05.04 MaleJill 1981.04.17 FemaleBell 1990.05.14 Female

DirectorName Date of birth Date of

deathTim Burton 1958.8.25  David Fincher 1962.8.28  Christopher Nolan 1970.7.30  

Page 8: CS562 Project #1 Assignment Date : October 11th, 2012 Due Date : October 28th, 2012 TA: Lee, Min-Joong.

Queries

Some queries are should be implemented using an embedded SQL method rather than using a single SQL statement or a trigger.

Unspecified queries can be implemented in any ways.

…4. Select the names of the movies whose actor are dead. (Use embedded SQL method)5. Select the names of the directors who cast the same actor more than once. (Translate this statement to a single SQL statement; do not use embedded SQL method)6. Select the names of the movies and the genres, where movies have the common genre. (Translate this statement to a single SQL statement. Use sub-query SQL)…

Page 9: CS562 Project #1 Assignment Date : October 11th, 2012 Due Date : October 28th, 2012 TA: Lee, Min-Joong.

Output-Example

Database created!

Table created!

Initial data inserted!

Statement : Winona Ryder won the “Best supporting actor” award in 1994

Translated SQL : INSERT xxxxxxxxxxxx

Updated tables

award table

xxx table

…..

Statement : xxxxx

Translated SQL : xxxx

….

awardID awardName

0000 Best supporting actor

You should show the results for translated inserts/deletes/up-dates queries and all the up-dated tables for each statement.

Before run your application, assume that the database is empty.

Page 10: CS562 Project #1 Assignment Date : October 11th, 2012 Due Date : October 28th, 2012 TA: Lee, Min-Joong.

Environments

Recommended environments Language : JAVA IDE : Eclipse DBMS : MySQL▪ JDBC download: http://dev.mysql.com/downloads/connector/j/

DBMS setting ▪ Database name : CS562_studentID (ex., CS562_20111234)▪ Root id : root // password : cs562▪ Tables are should be named as I descried in the initial data

table.▪ Database should be installed at localhost(local machine)

If cannot understand above description, read JDBC Introduction.

Page 11: CS562 Project #1 Assignment Date : October 11th, 2012 Due Date : October 28th, 2012 TA: Lee, Min-Joong.

Submission

Files to submit : cs562_studentid.zip includes the following files. Program source files README.txt▪ How to run your program.▪ What you have implemented and what you have not.▪ Your implementation assumption if there are any.

Submission E mail : [email protected] Mail subject : [cs562 project#1] studentid_name▪ ex) [cs562 project#1] 20111234_John

Page 12: CS562 Project #1 Assignment Date : October 11th, 2012 Due Date : October 28th, 2012 TA: Lee, Min-Joong.

Due date & Score

Due date : Oct. 28, 2012 Midnight Penalty : 20% per day

Score Create table processing (20%) Insert processing (20%) Update processing (15%) Query processing (15%) Delete processing (15%) README and comment (15%)

Page 13: CS562 Project #1 Assignment Date : October 11th, 2012 Due Date : October 28th, 2012 TA: Lee, Min-Joong.

Q & A