Student Number: Please fill out the identification section above as well as the one on the back page, and read the instructions below. Good Luck!

Similar documents
PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

ERwin and JDBC. Mar. 6, 2007 Myoung Ho Kim

e-pg Pathshala Subject: Computer Science Paper: Web Technology Module: JDBC INTRODUCTION Module No: CS/WT/26 Quadrant 2 e-text

UNIT-3 Java Database Client/Server

Good Luck! CSC207, Fall 2012: Quiz 3 Duration 25 minutes Aids allowed: none. Student Number: Lecture Section: L0101. Instructor: Horton

Good Luck! CSC207, Fall 2012: Quiz 1 Duration 25 minutes Aids allowed: none. Student Number:

This lecture. Databases - JDBC I. Application Programs. Database Access End Users

Student Number: Legibly write your name and student number on this page. Legibly write your name on the back page of this exam.

JDBC 3.0. Java Database Connectivity. 1 Java

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

JDBC Architecture. JDBC API: This provides the application-to- JDBC Manager connection.

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CSE 135. Three-Tier Architecture. Applications Utilizing Databases. Browser. App. Server. Database. Server

Working with Databases and Java

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CSC 207H Fall L Java Quiz Duration 25 minutes Aids allowed: none

Databases and MySQL. COMP 342: Programming Methods. 16 September Databases and MySQL

Part I: Stored Procedures. Introduction to SQL Programming Techniques. CSC 375, Fall 2017

Database Programming. Week 9. *Some of the slides in this lecture are created by Prof. Ian Horrocks from University of Oxford

Introduction to JDBC. JDBC: Java Database Connectivity. Why Access a Database with Java? Compilation. Six Steps. Packages to Import

Accessing databases in Java using JDBC

CSC 108H1 F 2010 Test 1 Duration 45 minutes Aids allowed: none. Student Number:

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Discuss setting up JDBC connectivity. Demonstrate a JDBC program Discuss and demonstrate methods associated with JDBC connectivity

13 Creation and Manipulation of Tables and Databases

Lecture 9&10 JDBC. Mechanism. Some Warnings. Notes. Style. Introductory Databases SSC Introduction to DataBases 1.

Enterprise Systems. Lecture 02: JDBC. Behzad BORDBAR

CS221 Lecture: Java Database Connectivity (JDBC)

Three-Tier Architecture

CSC System Development with Java. Database Connection. Department of Statistics and Computer Science. Budditha Hettige

Chapter 16: Databases

CSC 108H1 F 2009 Test 1 Duration 35 minutes Aids allowed: none. Student Number:

JDBC Programming: Intro

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science

Chapter 13 Introduction to SQL Programming Techniques

JAVA AND DATABASES. Summer 2018

SQL in a Server Environment

JDBC Java Database Connectivity is a Java feature that lets you connect

EMBEDDED SQL. SE 3DB3 Fall 2016 MICHAEL LIUT DEPARTMENT OF COMPUTING AND SOFTWARE MCMASTER UNIVERSITY

JDBC [Java DataBase Connectivity]

SQream Connector JDBC SQream Technologies Version 2.9.3

Database Application Development

Embedded SQL. csc343, Introduction to Databases Diane Horton with examples from Ullman and Widom Fall 2014

JDBC Drivers Type. JDBC drivers implement the defined interfaces in the JDBC API for interacting with your database server.

Student Number: UTORid: Question 0. [1 mark] Read and follow all instructions on this page, and fill in all fields.

Introduction to Relational Database Management Systems

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully.

Ghislain Fourny. Information Systems for Engineers 7. The ecosystem around SQL

JDBC. Oracle ODBC SP API SP API. SQL server C function calls. SQL server ODBC SP API. Oracle DSN Oracle ODBC Oracle

Spring 2013 CS 122C & CS 222 Midterm Exam (and Comprehensive Exam, Part I) (Max. Points: 100)

1. PhP Project. Create a new PhP Project as shown below and click next

DataBase Lab JAVA-DATABASE CONNECTION. Eng. Haneen El-masry

UNIVERSITY OF TORONTO Faculty of Arts and Science. Midterm Sample Solutions CSC324H1 Duration: 50 minutes Instructor(s): David Liu.

SQL: Data Definition Language. csc343, Introduction to Databases Diane Horton Fall 2017

Lab # 9. Java to Database Connection

Unit 3 - Java Data Base Connectivity

Introduction to Databases [p.3]

CS 474, Spring 2016 Midterm Exam #2

Writing your own Exceptions. How to extend Exception

Database Access with JDBC. Dr. Jens Bennedsen, Aarhus University, School of Engineering Aarhus, Denmark

3) execute() Usage: when you cannot determine whether SQL is an update or query return true if row is returned, use getresultset() to get the

COMPUTER SCIENCE III: ITCS 2304 FINAL EXAMINATION TIME: 2 HOURS

UNIT III - JDBC Two Marks

Database connectivity (II)

Lecture 27 10/30/15. CMPSC431W: Database Management Systems. Instructor: Yu- San Lin

SQL and Java. Database Systems Lecture 20 Natasha Alechina

COP4540 TUTORIAL PROFESSOR: DR SHU-CHING CHEN TA: H S IN-YU HA

Unit 2 JDBC Programming

Arrays. Eng. Mohammed Abdualal

Embedded SQL. csc343, Introduction to Databases Renée J. Miller and Fatemeh Nargesian and Sina Meraji Winter 2018

CMSC 433 Section 0101 Fall 2012 Midterm Exam #1

No Aids Allowed. Do not turn this page until you have received the signal to start.

Assertions, Views, and Programming. CS157A Chris Pollett Oct. 31, 2005.

DATABASE MANAGEMENT APPLICATIONS

The Basis of Data. Steven R. Bagley

OF VICTORIA EXAMINATIONS- DECEMBER 2010 CSC

Exam Duration: 2hrs and 30min Software Design

JDBC. Sun Microsystems has included JDBC API as a part of J2SDK to develop Java applications that can communicate with databases.

Ryerson University Vers HAL6891A-05 School of Computer Science CPS109 Midterm Test Fall 05 page 1 of 6

Database Applications. SQL/PSM Embedded SQL JDBC

Please note that if you write the mid term in pencil, you will not be allowed to submit a remark request.

CS 455 Midterm Exam 2 Fall 2016 [Bono] November 8, 2016

Database Applications (15-415)

Database Application Development

Relational Algebra. Relational Query Languages

The Relational Model. Suan Lee

More Database Programming. CS157A Chris Pollett Nov. 2, 2005.

Introduction to Computing II (ITI 1121) Final Examination

CIS 110 Fall 2014 Introduction to Computer Programming 8 Oct 2014 Midterm Exam Name:

LAB 3 Notes. Codd proposed the relational model in 70 Main advantage of Relational Model : Simple representation (relationstables(row,

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CSE344 Final Exam Winter 2017

Top 50 JDBC Interview Questions and Answers

VanillaCore Walkthrough Part 1. Introduction to Database Systems DataLab CS, NTHU

Database Programming Overview. COSC 304 Introduction to Database Systems. Database Programming. JDBC Interfaces. JDBC Overview

CSC 209H1 S 2012 Midterm Test Duration 50 minutes Aids allowed: none. Student Number: # 1: / 7

Enterprise JavaBeans. Layer:08. Persistence

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Non-interactive SQL. EECS Introduction to Database Management Systems

Transcription:

CSC 343H1S 2013 Test 2 Duration 50 minutes Aids allowed: none Last Name: Lecture Section: Day Student Number: First Name: Instructor: Horton Please fill out the identification section above as well as the one on the back page, and read the instructions below. Good Luck! There is an API on the back page that will help you with the JDBC question. You are welcome to use views. Comments are not necessary in your SQL or Java code, but may help us mark your answer. If you use any space for rough work or need to scratch out an answer, circle the part that you want us to mark. # 1: / 9 # 2: /12 # 3: / 6 TOTAL: /27 Total Pages = 8 Page 1 cont d...

Question 1. [9 marks] Consider the following schema: create table Department( did integer primary key, name text not null, division integer); create table Employee( eid integer primary key, name text not null, salary float, department integer references Department(dID)); -- Employee "manager" manages employee "junior". create table Manages( manager integer references Employee(eID), junior integer references Employee(eID), primary key(manager, junior)); -- This employee sold this amount on this day. create table Sales( eid integer references Employee(eID), day date, amount integer); Part (a) [4 marks] Imagine what would happen if someone were removed from the Employee table. Suppose that we want the following to occur automatically: Any tuple(s) that in the Manages table that record who manages this person should remain in the Manages table, but their junior column should become null. Any tuple(s) that in the Manages table that record who this person manages should be removed from the Manages table. Revise the DDL above to implement this reaction policy. Student #: Page 2 of 8 cont d...

Part (b) [3 marks] Consider this query: SELECT FROM Employee natural join Sales GROUP BY day, eid; Which of the following can go in the blank space shown? Circle either Can or Can t for each. eid Can Can t count(day) Can Can t average(amount) Can Can t name Can Can t max(salary) Can Can t department Can Can t Part (c) [1 mark] Write a SQL statement to increase the salary of every employee in the department with did 212 by 10,000. Part (d) [1 mark] According to the schema, must every employee have a manager? (No mark without an explanation.) Circle one: Yes No Explain your answer briefly Student #: Page 3 of 8 cont d...

Question 2. [12 marks] This question also uses the schema from question 1. It is summarized here in a very abbreviated fashion. Underscores indicate a primary key. Department(_dID_, name, division) Manages(_manager, junior_) manager references Employee(eID) junior references Employee(eID) Employee(_eID_, name, salary, department) department references Department(dID) Sales(eID, day, amount) eid references Employee(eID) 1. Write a query to produce output structured like this: managername managersalary juniorname juniorsalary -------------+---------------+------------+-------------- Include in it a row for every pair of employees A and B such that A manages B, A s salary is more than twice as high as B s salary, B s total sales are more than 100,000, and B doesn t manage anyone. Student #: Page 4 of 8 cont d...

2. Let s say that employee x is a level 1 report to employee y if y manages x, employee x is a level 2 report to employee y if y manages someone who manages x, and so on. Write a query to produce output structured like this: level totalsales -------+------------ It should have three rows: one for the total sales of all employees who are level 1 reports to Marissa Mayer, one for the total sales of her level 2 reports, and one for the total sales of her level 3 reports. If she has no reports at a given level, totalsales for that level should be 0. Student #: Page 5 of 8 cont d...

Question 3. [6 marks] The following Java program connects to a database conforming to the schema from question 1, and then reports the employee IDs of everyone who reports to Marissa Mayer, everyone who reports to Bill Gates, and everyone who reports to Sheryl Sandberg. Complete the program. Assume all appropriate imports have been done. IMPORTANT: There is an API at the back of the test. Marking of Java syntax will not be strict. class Company { public static void main(string args[]) throws IOException { String[] names = {"Marissa Mayer", "Bill Gates", "Sheryl Sandberg"}; Connection conn; try { Class.forName("org.postgresql.Driver"); // Assume a Connection to the database has been made and conn stores it. for (String who : names) { // Print the eid of everyone directly managed by who. } } } conn.close(); } catch (Exception e) { System.err.println("uh oh!" + e.getmessage()); } Student #: Page 6 of 8 cont d...

[Use the space below for rough work. This page will not be marked unless you clearly indicate the part of your work that you want us to mark.] Student #: Page 7 of 8 cont d...

Last Name: First Name: Abbreviated Java API: Connection: void close() Releases this Connection object s database and JDBC resources immediately Statement createstatement() Creates a Statement object for sending SQL statements to the database. PreparedStatement preparestatement(string sql) Creates a PreparedStatement object for sending parameterized SQL statements to the database. PreparedStatement (extends Statement): boolean execute() Executes the SQL statement in this PreparedStatement object, which may be any kind of SQL statement. ResultSet executequery() Executes the SQL query in this PreparedStatement object and returns the ResultSet object generated by the query. void setint(int parameterindex, int x) Sets the designated parameter to the given Java int value. void setstring(int parameterindex, String x) Sets the designated parameter to the given Java String value. ResultSet: void close() Releases this ResultSet object s database and JDBC resources immediately. int getint(int columnindex) Retrieves the int value of the designated column in the current row of this ResultSet. int getint(string columnlabel) Retrieves the int value of the designated column in the current row of this ResultSet. String getstring(int columnindex) Retrieves the String value of the designated column in the current row of this ResultSet. String getstring(string columnlabel) Retrieves the String value of the designated column in the current row of this ResultSet. boolean next() Moves the cursor froward one row from its current position. Statement: boolean execute(string sql) Executes the given SQL statement, which may return multiple results. ResultSet executequery(string sql) Executes the given SQL statement, which returns a single ResultSet object. Total Pages = 8 Page 8 End of Examination