Hello, I have a JAVA function that has two lists (Companies and Application

Hello,
I have a JAVA function that has two lists (Companies and Applications) as input parameters. Based on those input parameters, I have two "for" loops - one nested in another. That is because I want to check every input Application in every Company. Inside the "for" loop, I read from a database, and the result (that can be only one element) is put in a list called "list". So basically, the list gets filled with every iteration of the for cycles (assuming that the database check returned some value, otherwise, the list stays as it is, and i check the next element from the loops). My problem is: Every time i have more than one element in each of the "for" cycles, I get an empty list as a result. But if the input lists (Companies and Applications) are each filled with only one element, then the result returns a list with one element (which is correct). It seems like when I have more elements in the input lists, the result list gets overwritten and returns...

OriginalPostID-58422

OriginalPostID-58422

  Discussion posts and replies are publicly visible

Parents
  • ...t();
    ResultSet result = stm
    .executeQuery("SELECT a_id,sourceuser,alternativeuser,fromdate,todate,ap plication,company FROM alternativeusers1 where sourceuser = '"
    + Employees + "' and application = '" + mApplication[j] + "' and company = '" + mCompany[i]
    + "' and (('" + from_date + "' between fromdate and todate) or ('" + to_date + "' between fromdate and todate)) ");


    Application = new String();
    Application = "";

    while (result.next())
    {
    Application = result.getString("application");
    }

    if (Application != "")
    {
    String App = new String();
    App = Application;
    list.add(App);
    }

    result = null;
    stm.close();
    }
    }
    con.close();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    String[] returns = new String[list.size()];

    for(int m=0;m<list.size();m++)
    {
    returns[m] = (String)list.get(m);
    }


    return returns;

    }
Reply
  • ...t();
    ResultSet result = stm
    .executeQuery("SELECT a_id,sourceuser,alternativeuser,fromdate,todate,ap plication,company FROM alternativeusers1 where sourceuser = '"
    + Employees + "' and application = '" + mApplication[j] + "' and company = '" + mCompany[i]
    + "' and (('" + from_date + "' between fromdate and todate) or ('" + to_date + "' between fromdate and todate)) ");


    Application = new String();
    Application = "";

    while (result.next())
    {
    Application = result.getString("application");
    }

    if (Application != "")
    {
    String App = new String();
    App = Application;
    list.add(App);
    }

    result = null;
    stm.close();
    }
    }
    con.close();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    String[] returns = new String[list.size()];

    for(int m=0;m<list.size();m++)
    {
    returns[m] = (String)list.get(m);
    }


    return returns;

    }
Children
No Data