How can I iterate through the map and store the entries into mysql database. I have look for example but no luck an illustration would be wonderful. p.s the code works perfectly, the output is >> USD 1.5875 EUR 1.1919 ALL 166.2959
AMD 645.4025. I need to store the county code and their rate
AMD 645.4025. I need to store the county code and their rate
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.get("CCY") +" "+ ccyRate.get("RATE"));} } @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(); } } }