I am a newbie to Java, My problem is I am trying to insert currency rates into my MySQL database table called currency which contains two columns Currency_name and rate. The program fetches currency rate from finance yahoo API, I am facing The problem of storing the data into my database.
void checkRateAllAtEnd() throws Exception {
/** print message */
System.out.println("checkRateAllAtEnd :");
long start = System.nanoTime();
List<Callable<HashMap>> tasks = new ArrayList<Callable<HashMap>>();
for (final String ccy : CURRENCY) {
tasks.add(new Callable<HashMap>() {
public HashMap 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("Value of £1 in " + ccyRate.get("CCY") + " is " + ccyRate.get("RATE"));
}
I am lacking the credit to pass the values from hashmap to preparedStatement.
String sql="update currency set currency_name='"+Value1+"'";
preparedstatement=connection.prepareStatement(sql);
preparedstatement.execute();
I have the entire class here on this link fully functioning to keep the question clean >>linke<<<
this is the output of the programe which i would like to store into MYSQL Ideally i would like to store
ccyRate.get(“CCY”) and ccyRate.get(“RATE”)
checkRateAllAtEnd :
Value of £1 in AED is 5.9201
Value of £1 in AFN is 82.4359
Value of £1 in ALL is 171.681
Value of £1 in AMD is 650.4296
Value of £1 in ANG is 2.8849
Value of £1 in AOA is 154.4766
Value of £1 in ARS is 7.9438
Value of £1 in AUD is 1.5345
Your addCurrency method is wrong – Not only you’re not gaining anything by providing the preparedStatmenet as parameter , you’re not gaining anything when trying to close it,
as it is null at that point.
Please show us the exact error/exception you’re having and I’ll edit my answer accordingly.