$24
• INSTRUCTIONS
(1) This lab is graded.
(2) Use the student database that was created in Lab1.
(3) Instructions for downloading JDBC driver for MySQL:
(a) Download JDBC connector from https://dev.mysql.com/downloads/connector/j/ For Linux: Install using sudo apt install <.deb> file
(b) Your .jar will be in /usr/share/java
Set your CLASSPATH using the following command (for bash):
export CLASSPATH=$CLASSPATH:/usr/share/java/mysql-connector-java-8.0.15.jar
(c) To start a connection, use the following code:
String url = "jdbc:mysql://localhost:3306/<your database name>"; String username = "<your user name>";
String password = "<your password>";
Connection conn= DriverManager.getConnection(url, username, password);
• QUESTION 1
Consider the following relations:
Student(snum: integer, sname: string, major: string, level: string, age: integer)
Class(name: string, meets_at: time, room: string, fid: integer)
Enrolled(snum: integer, cname: string)
Faculty (fid: integer, fname: string, deptid: integer)
The meaning of these relations is straightforward; for example, Enrolled has one record per student-class pair such that the student is enrolled in the class.
(1) Write a Java application that lists all the tables and asks the user to select a table to print. Upon selection, the application must print the contents of the selected table in tabular form. [5 Marks]
(2) Write a Java application that runs the queries given below. Your application must handle error cases. If a query returns an error, the error must be displayed to the user. (Alternatively, you may write a separate application for each query.) [3*5=15 Marks]
(a) Ask the user to specify the name of a room. Print the names of all classes that meet in that room.
(b) Ask the user to specify the name of a course. Print the rooms and the times at which classes for that course will be conducted.
(c) Ask the user to specify the name of a faculty member. Print the names of the courses that that faculty member teaches.
.
1