1

私はJavaの初心者です。問題は、Currency_nameとrateの2つの列を含むcurrencyというMySQLデータベーステーブルに通貨レートを挿入しようとしていることです。プログラムはfinanceyahooAPIから為替レートを取得しますが、データベースにデータを保存するという問題に直面しています。

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"));
        }

ハッシュマップからpreparedStatementに値を渡すためのクレジットが不足しています。

        String sql="update currency set currency_name='"+Value1+"'";
        preparedstatement=connection.prepareStatement(sql); 
        preparedstatement.execute();

私はこのリンクのクラス全体が完全に機能して質問をきれいに保つようにしています>> linke <<<

これは私がMYSQLに保存したいプログラムの出力です理想的には私は保存したいです

ccyRate.get( "CCY")および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
4

1 に答える 1

0

addCurrencyメソッドが間違っています-preparedStatmenetをパラメーターとして指定しても何も得られないだけでなく、閉じようとしても何も得られません
。その時点ではnullであるためです。
あなたが抱えている正確なエラー/例外を私たちに示してください、そして私はそれに応じて私の答えを編集します。

于 2013-01-07T02:04:48.660 に答える