Question
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.
Java Code:
import java.sql.* ; import java.io.* ; import sqlj.runtime.* ; import sqlj.runtime.ref.* ; import oracle.sqlj.runtime.* ;
DefaultContext cntxt oracle.getConnection("
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.
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:@
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
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