import java.sql.*;
class solution1
{
  public static void main (String args [])
       throws SQLException, ClassNotFoundException
  {
    // Load the Oracle JDBC driver

    Class.forName ("oracle.jdbc.driver.OracleDriver");
    Connection conn = DriverManager.getConnection
      ("jdbc:oracle:thin:@localhost:1521:db",  "tpchr", "oracle");
    try{
          System.out.println( "Just started");
          Statement stmt = conn.createStatement ();
          ResultSet rset = stmt.executeQuery( "SELECT C_CUSTKEY, SUM(O_TOTALPRICE) FROM CUSTOMER JOIN ORDERS " +
                                              "ON C_CUSTKEY = O_CUSTKEY " + "GROUP BY C_CUSTKEY " + "HAVING C_CUSTKEY < 5 " +
                                              "AND SUM(O_TOTALPRICE) > 0" );
          double total_money = 0.0; 
          long customer_key = 0; 
          while (rset.next() ) 
          {
            customer_key = rset.getInt(1);
            total_money = rset.getDouble(2); System.out.println( "Customer: " + customer_key + "Money spent: " + total_money ); }
          }
    catch (SQLException e ) 
    {
       String errmsg = e.getMessage();
       System.out.println( errmsg ); 
    }
  }
}
