Check That a query returns exactly one row
843854Oct 14 2003 — edited Oct 16 2003I have to check that a statment return exactly one row before i can use the result of it. I must use the following parameters for the result set : ResultSet.TYPE_FORWARD_ONLY and ResultSet.CONCUR_READ_ONLY. Here is the way i think code it.
private void sqlprimCheckUniqueResultSet(ResultSet rs)
throws NoRowException, NotUniqueRowException {
try {
if (!rs.next()) {
throw new NoRowException();
}
if (rs.next()) {
throw new NotUniqueRowException();
}
rs = ((PreparedStatement)rs.getStatement()).executeQuery();
if (!rs.next()) {
throw new NoRowException();
}
} catch (SQLException e) {
throw ErrorHandler.rethrow(e, "......");
}
}
Is it good ? Someone have any advices ?
Thanks
claude.catonio@winterthur.be