Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE PLEASE PLEASE Submit only the SCREENSHOTS for the following java codes. Please do not re-write the java codes below. Just SCREENSHOTS only after executing!

PLEASE PLEASE PLEASE Submit only the SCREENSHOTS for the following java codes. Please do not re-write the java codes below. Just SCREENSHOTS onlyafter executing!

1. Consider the database shown in Figure 1.2, whose schema is shown in Figure 2.1. Write a program segment to read a students name and print his or her grade point average, assuming that A = 4, B = 3, C = 2, and D = 1 points. You can use SQLJ/JDBC with Java as the host language.

image text in transcribed

image text in transcribed

Java Code:

import java.sql.* ; import java.io.* ; import sqlj.runtime.* ; import sqlj.runtime.ref.* ; import oracle.sqlj.runtime.* ;

DefaultContext cntxt oracle.getConnection("", "", "", true) ; //connect to database with username and password DefaultContext.setDefaultContext(cntxt) ;

String name; int count = 0, total = 0;

#sql iterator Grades( char grade );

Grades grades;

name = readEntry("Enter a Student Name: ") ; try { grades = #sql{ select g.Grade into : grade from GRADE_REPORT g, STUDENT s where s.Name = :name and g.Student_number = s.Student_Number } ; } catch (SQLException se) { System.out.println("student name does not exist: " + name) ; Return ; }

while (grades.next()) { if (grades.grade=="A") { total+=4; } else if (grades.grade=="B") { total+=3; } else if (grades.grade=="C") { total+=2; } else if (grades.grade=="D") { total+=1; } count++; }

System.out.println("Average gpa: " + total/count);

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

2. Consider the library relational database schema in Figure 6.6. Write a program segment that retrieves the list of books that became overdue yesterday and that prints the book title and borrower name for each. You can use SQLJ/JDBC with Java as the host language.

image text in transcribed

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:@::","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 Figure 1.2 A database that stores student and course information. STUDENT 17 8 CS COURSE Course name Course_number Credit hours Intro to Computer Science CS1310 Data Structures MATH2410 SECTION MATH2410 CS1310 07 King 07 92 102 112 MATH2410 CS1310 08 Chang 08 Anderson 135 GRADE REPORT 17 112 17 119 102 135 PREREQUISITE MATH2410 CS1310 CS3320 Figure 1.2 A database that stores student and course information. STUDENT 17 8 CS COURSE Course name Course_number Credit hours Intro to Computer Science CS1310 Data Structures MATH2410 SECTION MATH2410 CS1310 07 King 07 92 102 112 MATH2410 CS1310 08 Chang 08 Anderson 135 GRADE REPORT 17 112 17 119 102 135 PREREQUISITE MATH2410 CS1310 CS3320

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

More Books

Students also viewed these Databases questions

Question

Discuss the process involved in selection.

Answered: 1 week ago

Question

Differentiate tan(7x+9x-2.5)

Answered: 1 week ago

Question

Explain the sources of recruitment.

Answered: 1 week ago

Question

Differentiate sin(5x+2)

Answered: 1 week ago

Question

Compute the derivative f(x)=1/ax+bx

Answered: 1 week ago