Skip to content

Instantly share code, notes, and snippets.

@nitindhar7
Created October 22, 2011 00:35
Show Gist options
  • Save nitindhar7/1305353 to your computer and use it in GitHub Desktop.
Save nitindhar7/1305353 to your computer and use it in GitHub Desktop.
ResultSet Pattern
public class UsersJDBCDao {
private static final String GET_ALL_USERS = "SELECT * FROM users";
public UsersResultSet getAllUsers() {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = getConnection();
ps = conn.prepareStatement(GET_ALL_ORDERS);
ps.setFetchSize(1000); // Fetch users lazily 1000-by-1000
rs = ps.executeQuery();
return new UsersResultSet(rs, ps, conn);
} catch (SQLException se) {
// Deal with exception
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment