0

我使用 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)打了数据库,并且完成这个过程需要很多时间。

什么是最有效的方法

4

0 回答 0