hi all,
i am using JDBC. When i get a ResultSet from the method Statement.executeQuery(sql), i'd like to know how many rows there are in the result set. I searched in the JDBC APIs documents, tried to find a method such as ResultSet.getRowCount(), but i failed. What i do now is like the following:
String sql = "SELECT name FROM myTable";
ResultSet set = stmt.executeQuery(sql);
int rowCount = 0;
if (set.last()==true) {
rowCount = set.getRow();
}
String[] names = new String[rowCount];
set.first();
for (int i=0; i<rowCount; i++) {
names[i] = set.getString("name");
set.next();
}
My method is not pretty at all. I'd like to know how to reimplement the code above in a more graceful way. thanks.