Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8704933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:13:59+00:00 2026-06-13T03:13:59+00:00

So I have an application that I start on 2PC. Each instance launches an

  • 0

So I have an application that I start on 2PC. Each instance launches an HSQLDB in server mode.

I’m trying to get the sales of different products.

So I query the local database and fill an arraylist with the name of the product and the number of sales.

Then I execute the same query on the other database on the other PC.

For 1 product, I so have two lines (each one correspond to one database).
Here, results are false but the execution time is ok.

In order to manage that, I did the following :

ResultSet rs2 = state2.executeQuery(produitsQuery);
while (rs2.next()) {
   for (int i = 0; i < produits.size(); i++) {
       obj = ((Object[]) produits.get(i));
       idpdt = (Integer) obj[1];

       if (idpdt == rs2.getInt(1)) {
           nb = (Integer) obj[3];
           valo = (Double) obj[4];

           nb += rs2.getDouble(4);
           valo += rs2.getDouble(5);
           produits.set(i, new Object[]{
               rs2.getString("famille"),
               rs2.getInt("id_pdt"),
               rs2.getString("nom_pdt"),
               nb,
               valo,
               s2.getString("sous_famille")});
           k = 1;
       }
    }
    if (k == 0) 
        produits.add(new Object[]{
            rs2.getString("famille"),
            rs2.getInt("id_pdt"),
            rs2.getString("nom_pdt"),
            rs2.getInt("nb"),
            rs2.getDouble("valo"),
            rs2.getString("sous_famille")});

}

Results are perfect but the execution time is very very slow and that’s a problem. I think it’s because I loop the entire arraylist at every row of the resultset.

What others solutions might I use to make the execution time faster?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:14:00+00:00Added an answer on June 13, 2026 at 3:14 am

    Why not put your first result set into a HashMap, keyed on idpdt (since that’s what you’re indexing by) ? A HashMap will provide O(1) lookups, rather than O(n).

    Your code would look like:

    while (r2.next()) {
       Object[] result = map.get(rs2.getInt(1));
       if (result != null) {
          ...
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF application that at start up inits a named pipe server
I have an application that the user can start in two different ways, as
I have an application that has many different types of objects that each persist
I have an application that depends on other .net assemblies. When I start the
I have application that makes different queries with different results so the caching in
I have Android application that on Service start implement followed code: ... Process process
I have an application that on a subsequent start detects if there's a process
I have to start x64 bit application that is located under c:\windows\system32 (it is
I have an application that consist of multiple components, each compiled into single DLL,
I have an application that needs to detect a shaking motion to start/restart its

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.