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

1
  • You have already got the answers. I would suggest to try prepared statements and bind variables. A quick starting point is here : stackoverflow.com/questions/687550/… Commented Jun 4, 2011 at 16:15

1 Answer 1

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) +"' ");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.