从数据库中检索数据时出现(PreparedStatement perst)问题

时间:2011-07-21 10:26:54

标签: java mysql

        query="select friend_uname from myfriends";//SELECT ALL THE FRIENDS OF THE USER
        System.out.println(query);
        rs=stmt.executeQuery(query);     

        query="select * from service_provider where source=\""+source+"\" and dest=\""+dest+"\"    and resources>0 and provider_name IN(?);";
        System.out.println(query);
        prest=conn.prepareStatement(query);

        while(rs.next())
        {
        x=rs.getString("friend_uname");//SELECT THE FRIEND NAMES OF THE USER ONE BY ONE...
        System.out.println("THE friend_uname IS"+ x);
        prest.setString(1,x);//SET THE iTH POSITION OF THE STRING AS THE FRIEND NAME
        }

1 个答案:

答案 0 :(得分:0)

尝试此查询

query="select * from service_provider where source=\""+source+"\" and dest=\""+dest+"\"  and resources>0 and provider_name IN(select friend_uname from myfriends)";

或尝试使用加入查询

query="select sp.* from service_provider sp, myfriends myfrnd where sp.source=\""+source+"\" and sp.dest=\""+dest+"\"  and sp.resources>0 and sp.provider_name=myfrnd.friend_uname";