RanRag
RanRag

Reputation: 49537

using arraylist inside mysql select statement

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

Upvotes: 1

Views: 2481

Answers (1)

Johan
Johan

Reputation: 76537

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) +"' ");

Upvotes: 2

Related Questions