// To compile and run this program on an MCS Department Linux machine: // javac CandCount.java // env LD_LIBRARY_PATH=/Net/gac/home/m/a/max/instantclient_11_1 \ // CLASSPATH=/Net/gac/home/m/a/max/instantclient_11_1/ojdbc5.jar:. \ // java CandCount minOffice maxOffice import java.sql.*; public class CandCount{ public static void main(String[] args){ try{ Class.forName("oracle.jdbc.OracleDriver"); // connect to our server with username "anon" and password "anon": Connection myCon = DriverManager.getConnection ("jdbc:oracle:oci:@//thebe.gac.edu:1521/xe", "anon", "anon"); PreparedStatement ps = myCon.prepareStatement ("select count(*), min(office_title)" + " from sos.candidates" + " where office_id >= ?" + " and office_id <= ?" + " group by office_id, county_id"); ps.setString(1, args[0]); ps.setString(2, args[1]); ResultSet rs = ps.executeQuery(); while(rs.next()){ System.out.print(rs.getString(2)); System.out.print(": "); System.out.println(rs.getInt(1)); } } catch(Exception e){ System.err.println(e); System.exit(1); } } }