// To compile and run this program on an MCS Department Mac OS X machine: // // Option 1: use eclipse as described in web page linked from the homework. // // Option 2: follow the below instructions: // // (1) Launch a terminal // // (2) Set up the environment based on the shell you use: // // (a) if you are using bash (probably the case) do: // // export DYLD_LIBRARY_PATH=/Users/Shared/instantclient_11_2 // export CLASSPATH=/Users/Shared/instantclient_11_2/ojdbc6.jar:. // // (b) if you are using tcsh: // // setenv DYLD_LIBRARY_PATH /Users/Shared/instantclient_11_2 // setenv CLASSPATH /Users/Shared/instantclient_11_2/ojdbc6.jar:. // // (3) Compile the program (assuming you are in the directory containing it): // // javac CountCandidates.java // // (4) Run the program: // // java CountCandidates pattern import java.sql.*; public class CountCandidates{ public static void main(String[] args){ try{ Class.forName("oracle.jdbc.OracleDriver"); // connect to our server with username "anonymous" and password "anon": Connection myCon = DriverManager.getConnection ("jdbc:oracle:oci:@//thebe.virtual.gac.edu:1521/xe", "anonymous", "anon"); PreparedStatement ps = myCon.prepareStatement("select office_title, count(*)" + " from sos.candidates" + " where office_title like ?" + " group by office_title" + " order by office_title"); ps.setString(1, args[0]); ResultSet results = ps.executeQuery(); while(results.next()){ System.out.println(results.getString(1) + ": " + results.getInt(2)); } } catch(Exception e){ e.printStackTrace(); System.exit(1); } } }