DB使用OJDBC检索可变数量的输入

时间:2014-03-07 17:26:25

标签: java ojdbc

我使用OJDBC从数据库中检索数据到一组给定的主键。为了使算法有效,我将循环限制在给定的集合而不是检索整个表。

我这样做

for (Integer customer : customers){
            String selectStatement= "SELECT * FROM table WHERE customerID ="+customer;
            processCustomer(selectStatement,statement);
        }
        connection.close();
        System.out.println("Done");
    }

    catch (SQLException e){
        System.out.println("Connection Failed! Check output console");
        System.out.println(e.getMessage());

    }

processCustomer方法根据我的需要处理Query并填充HashMap。

我认为这不是最佳做法,因为我为每个客户点击了数据库(可达到100k),并且需要花费大量时间才能完成此过程。

最有效的方法是什么

0 个答案:

没有答案