import java.sql.*;

public class JoltReport {
    public static void main (String args[]) {
        String URL = "jdbc:odbc:CafeJolt";
        String username = "";
        String password = "";

        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        } catch (Exception e) {
            System.out.println("Failed to load JDBC/ODBC driver.");
            return;
        }

        Statement stmt = null;
        Connection con=null;
        try {
            con = DriverManager.getConnection (
                URL,
                username,
                password);
            stmt = con.createStatement();
        } catch (Exception e) {
            System.err.println("problems connecting to "+URL);
        }

        try {
            ResultSet result = stmt.executeQuery(
                "SELECT programmer, cups FROM JoltData ORDER BY cups DESC;");
            result.next();  // move to first row
            String name = result.getString("programmer");
            int cups = result.getInt("cups");
            System.out.println("Programmer "+name+
                " consumed the most coffee: "+cups+" cups.");

            result = stmt.executeQuery(
                "SELECT cups FROM JoltData;");

            // for each row of data
            cups = 0;
            while(result.next()) {
                cups += result.getInt("cups");
            }
            System.out.println("Total sales of "+cups+" cups of coffee.");

            con.close();
        }
        catch (Exception e) {
          e.printStackTrace();
        }
    }
}

