1

I have a login arraylist where i have stored users loginid using following mysql query

Code:

query = "select LoginID from issuedeposit id where id.DueDate < CURDATE()";

    result = statement.executeQuery(query);

    while(result.next())
    {
        String loginid = result.getString(1);
        loginarray.add(loginid);
    }

now I want to use the loginid values stored in the above arraylist to fetch users emailid form other table. I am using following query

Code:

 for(int i=0;i<=loginarray.size();i++)
    {

        res = statement1.executeQuery("select EmailID form studentaccount sa where sa.LoginID = '"+ loginarray.get(i) +"' ");

        String email = res.getString(1);
        emailarray.add(email);       

    }

but am getting error in the above query. So have i correctly used the for loop or it should be used inside the query...? I am using JDBC and MySql

RanRag
  • 48,359
  • 38
  • 114
  • 167
  • You have already got the answers. I would suggest to try prepared statements and bind variables. A quick starting point is here : http://stackoverflow.com/questions/687550/preparedstatements-and-performance – Jayan Jun 04 '11 at 16:15

1 Answers1

2
res = statement1.executeQuery("select EmailID form studentaccount sa 
where sa.LoginID = '"+ loginarray.get(i) +"' ");

Should be

res = statement1.executeQuery("select EmailID FROM studentaccount sa 
where sa.LoginID = '"+ loginarray.get(i) +"' ");
Johan
  • 74,508
  • 24
  • 191
  • 319