Skip to content

Instantly share code, notes, and snippets.

@nitindhar7
Created October 22, 2011 00:41
Show Gist options
  • Select an option

  • Save nitindhar7/1305364 to your computer and use it in GitHub Desktop.

Select an option

Save nitindhar7/1305364 to your computer and use it in GitHub Desktop.
ResultSet Design Pattern: retrieving records
public class UsersResultSet {
private ResultSet _rs;
private PreparedStatement _ps;
private Connection _conn;
public UsersResultSet(ResultSet rs, PreparedStatement ps, Connection conn) {
_rs = rs;
_ps = ps;
_conn = conn;
}
public Order getNextUser() {
User user = null;
try {
if (_rs.next()) {
user = new User();
// ... build user from rs row ...
}
} catch (SQLException se) {
// Deal with exception
}
return user;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment