Write the following SQL queries in Java Here are the tables: classroom(building, room number, capacity) department(dept_name, building, budget) course(course id, title, dept_name, credits) instructor(ID, name,
Write the following SQL queries in Java
Here are the tables:
classroom(building, room number, capacity)
department(dept_name, building, budget)
course(course id, title, dept_name, credits)
instructor(ID, name, dept_name, salary)
section(course_id, sec_id, semester, year, building, room_number, time_slot_id)
teaches(ID, course_id, sec_id, semester, year)
student(ID, name, dept_name, tot_cred)
takes(ID, course_id, sec_id, semester, year, grade)
advisor(s_ID, i_ID)
time_slot(time_slot_id, day, start_hr, start_min, end_hr, end_min)
prereq(course_id, prereq_id)
Here is the Queries
Query 7: Find the first and the last semesters For each student, find the first semester and the last semester in which he/she has taken a course. The key to this query is to find a way to compare three different semesters (Spring, Summer, and Fall) in a year. Combine the semester and the year information in one field in your result. Here is the correct query result for your reference:
Here is the startup java code
import java.io.*; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.sql.CallableStatement; import java.util.*; import java.lang.String; public class MyQuery { private Connection conn = null; private Statement statement = null; private ResultSet resultSet = null; public MyQuery(Connection c)throws SQLException { conn = c; // Statements allow to issue SQL queries to the database statement = conn.createStatement(); }
public void findFirstLastSemester() throws SQLException { } public void printFirstLastSemester() throws IOException, SQLException { System.out.println("******** Query 7 ********"); } }id name First_Semester Last_Semester 00128 Zhang Fall 2009 Fall 2009 12345 Shankar Spring 2009 Spring 2010 19991 Brandt Spring 2010 Spring 2010 23121 Chavez Spring 2010 Spring 2010 44553 Peltier Fall 2009 Fall 2009 45678 Levy Fall 2009 Spring 2010 54321 Williams Spring 2009 Fall 2009 55739 Sanchez Spring 2010 Spring 2010 76543 Brown Fall 2009 Spring 2010 76653 Aoi Spring 2009 Spring 2009 98765 Bourikas Fall 2009 Spring 2010 98988 Tanaka Summer 2009 Summer 2010
Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started