public static double getMedianTestScore(int testID)
throws SQLException
{
Logger log = Logger.getLogger();
boolean loggingEnabled = log.isLoggingEnabled();
Median median = new Median();
ArrayList arraylist = new ArrayList();
Connection conn = getDefaultConnection();
try {
log.enableLogging( false );
PreparedStatement ps = Utils.prepare
(
conn,
"select tk.score\n" +
"from TestTaking tk, LastTaking lt\n" +
"where tk.takingID = lt.takingID\n" +
"and tk.testID = ?\n"
);
ps.setInt( 1, testID );
ResultSet rs = ps.executeQuery();
while( rs.next() )
{
arraylist.add(new Double(rs.getDouble(1)));
}
Utils.close(rs);
Utils.close(ps);
}
finally
{
log.enableLogging( loggingEnabled );
}
int count = arraylist.size();
double values[] = new double[ count ];
for ( int i = 0; i < count; i++)
{ values[ i ] = ((Double)arraylist.get(i)).doubleValue(); }
return median.evaluate( values );
}