KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ashkelon > pages > StatsAuthors


1 package org.ashkelon.pages;
2
3 import org.ashkelon.*;
4 import org.ashkelon.db.*;
5
6 import java.util.*;
7 import java.sql.*;
8
9 /**
10  * @author Eitan Suez
11  */

12 public class StatsAuthors extends Page
13 {
14    public StatsAuthors()
15    {
16       super();
17    }
18    
19    public String JavaDoc handleRequest() throws SQLException
20    {
21       request.setAttribute("classCounts", getAuthorStats());
22       return null;
23    }
24    
25    private static int MAX_ROWS = 50;
26    
27    public List getAuthorStats() throws SQLException
28    {
29       String JavaDoc sql = DBMgr.getInstance().getStatement("authorstats");
30       
31       Statement stmt = conn.createStatement();
32       stmt.setMaxRows(MAX_ROWS);
33        // in this case MAX_ROWS is the right thing to do.
34
// i want the top 50 authors
35

36       ResultSet rset = stmt.executeQuery(sql);
37       
38       List stats = new ArrayList(MAX_ROWS);
39       
40       List info = null;
41       
42       Author author = null;
43       while (rset.next())
44       {
45          info = new ArrayList(2);
46          author = new Author(rset.getString(1));
47          author.setId(rset.getInt(2));
48          info.add(author);
49          info.add(rset.getString(3));
50          stats.add(info);
51       }
52       
53       return stats;
54    }
55    
56 }
57
Popular Tags