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

  • ... empty. Why is that?
    Thank you in advance. Now here is the code:


    @Function
    public String[] GetEmployeeApplication(ServiceContext sc,
    @Parameter String SQLServer, @Parameter String DatabaseName,
    @Parameter String UserName, @Parameter String Password,
    @Parameter @UserDataType String SourceUser,
    @Parameter String[] Applications,
    @Parameter String[] Companies,
    @Parameter java.sql.Timestamp From_Date,
    @Parameter java.sql.Timestamp To_Date) {
    Connection con = getConnection("jdbc:sqlserver://"+SQLServer+";databaseName=" +DatabaseName+ ";user="+UserName+";password="+Password);

    String Application = "";
    String Employees = SourceUser;
    String[] mApplication = Applications;
    String[] mCompany = Companies;
    java.sql.Timestamp from_date = From_Date;
    java.sql.Timestamp to_date = To_Date;
    java.util.ArrayList<String> list = new ArrayList<String>();
    try {

    for (int i = 0; i < mCompany.length; i++) {

    for (int j = 0; j < mApplication.length; j++) {


    Statement stm = con.createStatemen...
  • ...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;

    }