Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the following SQL queries in Java The ID's of all tables reference each other It must use Subqueries when possible Here are the tables:

Write the following SQL queries in Java

The ID's of all tables reference each other

It must use Subqueries when possible

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

Find the name(s) of instructor(s) who has (or have) taught the most number of courses (there may be more than one such instructor). You cannot use ORDER BY and LIMIT in your SQL. Here is the correct query result for your reference:

image text in transcribed

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 findFall2009Students() throws SQLException { String query = "select distinct name from student natural join takes where semester = \'Fall\' and year = 2009;"; resultSet = statement.executeQuery(query); } public void printFall2009Students() throws IOException, SQLException { System.out.println("******** Query 0 ********"); System.out.println("name"); while (resultSet.next()) { // It is possible to get the columns via name // also possible to get the columns via the column number which starts at 1 String name = resultSet.getString(1); System.out.println(name); } } public void findGPAInfo() throws SQLException { String query = "select " + " " + " s.ID, s.name, sum(c.credits*t.grade)/sum(c.credits) " + " " + "from " + " student as s inner join " + " ( " + " select " + " ID, course_id, " + " case " + " when grade='A' then 4.0 " + " when grade='A-' then 3.67 " + " when grade='B+' then 3.33 " + " when grade='B' then 3.0 " + " when grade='B-' then 2.67 " + " when grade='C+' then 2.33 " + " when grade='C' then 2.0 " + " when grade='C-' then 1.67 " + " when grade='D+' then 1.33 " + " when grade='D' then 1.0 " + " when grade='D-' then 0.67 " + " when grade='F' then 0.0 " + " else 0 " + " end as grade " + " from takes " + " ) as t " + " " + " on s.ID = t.ID and t.grade is not null " + " inner join course as c on c.course_id = t.course_id " + " " + "group by s.ID, s.name"; resultSet = statement.executeQuery(query); } public void printGPAInfo() throws IOException, SQLException { System.out.println("******** Query 1 ********"); while (resultSet.next()) { String id = resultSet.getString(1); String name = resultSet.getString(2); String gpa = resultSet.getString(3); System.out.printf("%s %s %s ", id, name, gpa); } } 
public void findBusyInstructor() throws SQLException { } public void printBusyInstructor() throws IOException, SQLException { System.out.println("******** Query 3 ********"); }
}

The methods being worked on is findBusyInstructor() and printBusyInstructor(), thank you!

name Srinivasan Brandt

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions