在mysql select语句中使用arraylist [英] using arraylist inside mysql select statement

查看:176
本文介绍了在mysql select语句中使用arraylist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个登录名arraylist,其中使用以下mysql查询存储了用户loginid

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

代码:

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);
    }

现在我要使用存储在above arraylist中的loginid值来获取用户的other表的emailid.我正在使用以下查询

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

代码:

 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);       

    }

但在上述查询中出现错误.所以我正确使用了for loop还是应该在查询中使用它?? 我正在使用JDBC和MySql

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

应该是

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

这篇关于在mysql select语句中使用arraylist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆