import java.sql.*; import oracle.sqlj.runtime.Oracle; import sqlj.runtime.ref.DefaultContext; class GpaJDBC { public static void main (String args[]) throws SQLException { Connection conn=null;; PreparedStatement ps=null; ResultSet rs=null; double gpa; int ncourses; // set the default connection to the URL, user, and password // specified in your connect.properties file Oracle.connect(GpaJDBC.class, "sonconnect.properties"); conn = DefaultContext.getDefaultContext().getConnection(); Statement stmt = conn.createStatement (); // Select the grade column from the transcripts table ResultSet rset = stmt.executeQuery ("select * from Transcripts "); while (rset.next()) { System.out.println(rset.getString(1).toString() + rset.getString(2).toString() + rset.getString(3).toString() + rset.getString(4).toString()); } rset.close(); rset = stmt.executeQuery ("select grade from Transcripts "+ "WHERE studid = " + args[0]); // Initialize needed values gpa = 0.0; ncourses = 0; // Proceessing the result set (cursor) while (rset.next()) { if (rset.getString(1).compareTo("A")==0) { System.out.println("Is an A :-)"); gpa += 4.0; ncourses += 1; } if (rset.getString(1).compareTo("B")==0) { System.out.println("Is an B :-)"); gpa += 3.0; ncourses += 1; } if (rset.getString(1).compareTo("C")==0) { System.out.println("Is an C :-)"); gpa += 2.0; ncourses += 1; } if (rset.getString(1).compareTo("D")==0) { System.out.println("Is an D :-)"); gpa += 1.0; ncourses += 1; } if (rset.getString(1).compareTo("F")==0) { System.out.println("Is an F :-)"); gpa += 0.0; ncourses += 1; } } gpa = gpa / ncourses; System.out.println("Cumulative GPA of " + args[0] + " is " + gpa); // Close the RseultSet rset.close(); // Close the Statement stmt.close(); // Close the connection conn.close(); } }