Db2计数(*)AS +查询

时间:2015-11-23 02:11:59

标签: java db2

我在查询方面遇到了困难。我想做的就是这个。

public ObservableList<Query_3_11> getQuery_3_11() {
    ObservableList<Query_3_11> query_3_11List = FXCollections.observableArrayList();
    try {
        rs = stmt.executeQuery("SELECT town, COUNT(*) AS numofclients FROM Clients GROUP BY town ORDER BY numofclients DESC");
        while (rs.next()) {
            Query_3_11 query_3_11 = new Query_3_11();
            query_3_11.setMiasto(rs.getString("town"));
            query_3_11.setliczbaKlientow(rs.getInt("numofclients"));
            query_3_11List.add(query_3_11);
        }
    } catch (SQLException ex) {
        Logger.getLogger(DBConnector.class.getName()).log(Level.SEVERE, null, ex);
    }
    return query_3_11List;

基本上我的程序打印出城市的名称,但是客户编号列中有空格。这是一张照片。

screenshot of gui

这是查询类。

public class Query_3_11 {

private String town;
private int numofclients;

public String getTown() {
    return town;
}

public void setTown(String town) {
    this.town = town;
}

public int getnumofclients() {
    return numofclients;
}

public void setnumofclients(int numofclients) {
    this.numofclients = numofclients;
}
}  

如果我忘了重要的事情,请告诉我。这是我的第一个java程序。提前谢谢。

0 个答案:

没有答案