开发者

using arraylist inside mysql select statement

开发者 https://www.devze.com 2023-03-10 04:13 出处:网络
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()\";

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


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号