Question

In: Computer Science

Question 2: consider the following library relational database schema Write a program segment to retrieves the...

Question 2: consider the following library relational database schema Write a program segment to retrieves the list of books that became overdue yesterday and that prints the book title and borrower name for each.

1- Use JDBC with Java as the host language

Solutions

Expert Solution

Answer:

Java Code:

package com.java2novice.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class MyResultSetEx //Main Class
{

    public static void main(String a[]) //Main Function
{
         
        try
   {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection con = DriverManager.getConnection("jdbc:oracle:thin:@<hostname>:<port num>:<DB name>","user","password"); // Provide the database name,username and password details to establish the connection with database
            Statement stmt = con.createStatement();
            System.out.println("Created DB Connection...."); //Displaying if connection is established with database
            ResultSet rs = stmt.executeQuery("SELECT BK.Title, BW.Name FROM BOOK_LOANS BL JOIN BORROWER BW ON BL.Card_no=BW.Card_no JOIN BOOK BK ON BL.Book_id=BK.Book_id WHERE BL.Due_date < SYSDATE - 1;"); //SQL query to fetch book title and borrower name for whom due date was yesterday
            while(rs.next())
   {
                System.out.println(rs.getString(1)); //Printing the book title
                System.out.println(rs.getString(2)); //Printing the borrower name
            }
            rs.close();
            con.close(); //Closing the connection with database
        }
  catch (ClassNotFoundException e)
  {
            System.err.print("SQLException: ");
   e.printStackTrace();
        } catch (SQLException e)
  {
            System.err.print("SQLException: ");
   e.printStackTrace();
        }
    }
}


Related Solutions

• Relational Schema Create a relational database schema consisting of the four relation schemas representing various...
• Relational Schema Create a relational database schema consisting of the four relation schemas representing various entities recorded by a furniture company.   Write CREATE TABLE statements for the following four relation schemas. Define all necessary attributes, domains, and primary and foreign keys. Customer(CustomerID, Name, Address) FullOrder(OrderID, OrderDate, CustomerID) Request(OrderID, ProductID, Quantity) Product(ProductID, Description, Finish, Price) You should assume the following: Each CustomerID is a number with at most three digits, each OrderID is a number with at most five digits,...
Consider the following relational database schema:             employee(employee-name, employee-id, street, e-city)             works(employee-
Consider the following relational database schema:             employee(employee-name, employee-id, street, e-city)             works(employee-id, company-id, salary)             company(company-name, company-id, c-city)             manages(employee-id, manager-id) Specify the following queries on this database schema using the relational operators we discussed in class. Write your answers on a separate sheet of paper in the order that they are specified below. Retrieve the name and address of employees who work for First Bank Corporation. Retrieve the name, street address, and city of residence of all employees...
Database: Question 11 Using the ERD from problem 10, create the relational schema.(Create an appropriate collection...
Database: Question 11 Using the ERD from problem 10, create the relational schema.(Create an appropriate collection of attributes for each of the entities. Make sure you use the appropriate naming conventions to name the attributes.)
Given the following relational schema, write queries in SQL to answer the English questions. There is...
Given the following relational schema, write queries in SQL to answer the English questions. There is a shipment database on the MySQL server. You can also use the DDL for MySQL. You must only submit the SQL for your answers but you can include the query output as well to help the TA with marking. Customer(cid: integer, cname: string, address: string, city: string, state: string) Product(pid: integer, pname: string, price: currency, inventory: integer) Shipment(sid: integer, cid: integer, shipdate: Date/Time) ShippedProduct(sid:...
Given the following relational schema, write queries in SQL to answer the English questions. There is...
Given the following relational schema, write queries in SQL to answer the English questions. There is a shipment database on the MySQL server. You can also use the DDL for MySQL. You must only submit the SQL for your answers but you can include the query output as well to help the TA with marking. Customer(cid: integer, cname: string, address: string, city: string, state: string) Product(pid: integer, pname: string, price: currency, inventory: integer) Shipment(sid: integer, cid: integer, shipdate: Date/Time) ShippedProduct(sid:...
Consider the following relational schema about a University (the primary keys are underlined and foreign keys...
Consider the following relational schema about a University (the primary keys are underlined and foreign keys are italic) STUDENT(StudentID, name, major, year, age) CLASS(ClassName, meetsAt, room, LecturerID) ENROLLED(StudentID, ClassName, mark) LECTURER(LecturerID, name, DepartmentID) DEPARTMENT(DepartmentID, name) Write the SQL statements for the following query: B1. Find the age of the oldest student. B2. Find the ID’s of lecturers whose name begins with “K” \ B3. Find the age of the youngest student who is enrolled in Mechatronics. B4. Find the age...
QUESTION: The following tables describe the content of a relational database: a) Identify and classify the...
QUESTION: The following tables describe the content of a relational database: a) Identify and classify the tables as either entity or relationship The first step in building an E-R model is to identify the entities. Having identified the entities, the next step is to identify all the relationships that exist between these entities. Using the content of the relational database above: b) Using the relations in the relational database, explain how one can transform relationship in E-R model into a...
Consider the following database schema for a BOOKSTORE database: Books (bookid, title, author, year) Customers (customerid,...
Consider the following database schema for a BOOKSTORE database: Books (bookid, title, author, year) Customers (customerid, name, email) Purchases (customerid, bookid, year) Reviews (customerid, bookid, rating) Pricing (bookid, format, price) The Books relation stores information about books sold by the bookstore. Note that bookid is the primary key. An example tuple is as follows: (105, 'JAVA PROGRAMMING', 'JOHN DOE', 2001) The Customers relation stores information about the customers of the bookstore. Note that customerid is the primary key. An example...
Consider the following relational schema (the primary keys are underlined and foreign keys are italic) ITEM(ItemName,...
Consider the following relational schema (the primary keys are underlined and foreign keys are italic) ITEM(ItemName, ItemType, ItemColour) DEPARTMENT(Deptname, DeptFloor, DeptPhone, Manager) EMPLOYEE(EmpNo, EmpFname, EmpSalary, DeptName, SupervisedBy) SUPPLIER(SupNo, SupName) SALE(SaleNo, SaleQty, ItemName, DeptName) DELIVERY(DeliNo, DeliQty, ItemName, DeptName, SupNo) Write the SQL statements for the following queries: C1. Find the names of items sold on first and second floors. [1 mark] C2. For each department, list the department name and average salary of the employees where the average salary of the...
Consider the schemas of the following relational database for a company. The company has different departments...
Consider the schemas of the following relational database for a company. The company has different departments at different cities in different states: employee(employee-id, dept-id, name, street-num, street-name, city, state, zip, salary) department(dept-id, dept-name, city, state) manager(manager-id, employee-id) NOTES: manager-id in the manager relation is a foreign key to the employee relation. employee-id in the manager relation is a foreign key to the employee relation. dept-id in the employee relation is a foreign key to the department relation. An employee belongs...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT