Hello,
I tried to count the rows of each attribute which called "wbuch", any way i use the following sql request:
Java Code:
SELECT wbuch, COUNt(*) FROM myTable GROUP BY wbuch;
And the result was the following table:
+-------+----------+-----+
| wbuch | COUNt(*) |
+-------+-----------------+
| 12 | 15 |
| 13 | 334 |
| 15 | 20 |
| 16 | 488 |
| 17 | 16 |
| 20 | 252 |
| 21 | 24 |
| 23 | 599 |
| 30 | 599 |
| 31 | 508 |
| 33 | 599 |
| 34 | 491 |
| 35 | 571 |
| 36 | 643 |
| 37 | 152 |
| 46 | 419 |
+-------+------------------+
any way i want to store the row number's of each "wbuch" in arry list, but i didnt get it
Java Code:
public List<Integer> WbSeiten(){
private List<Integer> wbList = new ArrayList<>();
int rowCount = 0;
try (Statement stmt = con.createStatement();) {
String sql = "SELECT wbuch, COUNt(*) FROM myTable "
+ "GROUP BY wbuch";
ResultSet result = stmt.executeQuery(sql);
while (result.next()) {
rowCount =result.getInt("COUNt(*)");
wbList.add(rowCount);
}
} catch (SQLException e) {
}
return wbList;
}
what is wrong with my snippet ?? And how to do it correctly
No comments:
Post a Comment