Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9152811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:08:44+00:00 2026-06-17T12:08:44+00:00

sorry I am a newbie I have been looking for an example on how

  • 0

sorry I am a newbie I have been looking for an example on how I can iterate hashmap and store the entities into MySQL database. the blow code downloads currency rate which I would like to store into my database. the output is

{CCY=USD, RATE=1.5875}
{CCY=EUR, RATE=1.1919}
{CCY=ALL, RATE=166.2959}
{CCY=AMD, RATE=645.4025}

how can I iterate the HashMap and store it into my database? an illustration would be nice or source similar to this scenario.

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

public class Rate {
    /** list of string array containing IOSCurrencyCodes*/
        final String[] CURRENCY = new String[] { "USD","EUR","ALL","AMD",};

        @SuppressWarnings("rawtypes")
        void checkRateAllAtEnd() throws Exception {     
                List<Callable<HashMap>> tasks = new ArrayList<Callable<HashMap>>();
                for (final String ccy : CURRENCY) {
                        tasks.add(new Callable<HashMap>() {
                                public HashMap<String, Comparable> call() throws Exception {
                                        return getRates(ccy);
                                }
                        });
                }
                ExecutorService executorPool = Executors.newCachedThreadPool();
                final List<Future<HashMap>> listRates = executorPool.invokeAll(tasks, 3600, TimeUnit.SECONDS);

                for (Future<HashMap> rate : listRates) {
                        HashMap ccyRate = rate.get();

                        System.out.println(ccyRate);
                     }
                }
                @SuppressWarnings("rawtypes")
                public HashMap<String, Comparable> getRates(String ccy) throws Exception {
                        URL url = new URL("http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=GBP"
                                                        + ccy + "=X");
                        BufferedReader reader = new BufferedReader(new InputStreamReader(
                                        url.openStream()));

                        String data = reader.readLine();
                        String[] dataItems = data.split(",");
                        Double rate = Double.valueOf(dataItems[1]);

                        HashMap<String, Comparable> ccyRate = new HashMap<String, Comparable>();
                        ccyRate.put("CCY", ccy);
                        ccyRate.put("RATE", rate);

                        return ccyRate;           
                }
        public static void main(String[] args) {
            Rate ccyRate = new Rate();
                try {
                       //ccyConverter.checkRateSequential();
                       ccyRate.checkRateAllAtEnd();
                } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:08:45+00:00Added an answer on June 17, 2026 at 12:08 pm

    Map provides entrySet method which is very useful to iterate over a map.

    Map#entrySet returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress.

    ref – link

    Code –

    HashMap<String, Comparable> ccyRate = new HashMap<String, Comparable>();
    for(Map.Entry<String, Comparable> entry: ccyRate.entrySet){
        System.out.println(entry.getKey()+" - "+entry.getValue());
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a drupal newbie and have been looking for drupal themes for my
EDIT: I'm sorry, I've made a newbie mistake, and have been changing the value
A newbie here: sorry if the question is too simple, been looking in tutorials
Sorry for this newbie question, but I can't find on google what I need
Sorry, newbie question I know, however I've currently got mySQL results only showing when
Sorry for this newbie question but I cannot figure how I can do this..
Sorry for the newbie question. I have a UITabBar in my main window view
I have no experience with the Facebook API, so sorry for the newbie question:
Sorry for the newbie question. I have define a table in a following way
Sorry but iam an JS Newbie (-: I have to animate some span tags

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.