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?