title: how to concatenate dynamic value in nested sql statement in java?
body: <p>I have this code:<br></p>
  
  <pre><code>long userID = user.getId();
  String query = "select userclient.username from twitter_content.userclient where     userclient.userid = " +
          "(select follower.followerid from twitter_content.follower where follower.followerid = userclient.userid and follower.userid = "+userID+")";
  </code></pre>
  
  <p>I want to use userID as part of the query in the Where clause,but I seem to be not concatenating userID(I want it it to be read as a dynamic value,and not a String)properly.Could anybody give some guidance on doing it?</p>
  
  <p>EDIT:<br>
  This is the full source code:</p>
  
  <pre><code>public ArrayList&lt;Post&gt; retrieveFollowerDB(String userName){
      ArrayList&lt;Post&gt; postArray = new ArrayList&lt;Post&gt;();
      ArrayList&lt;Integer&gt; intArray = new ArrayList&lt;Integer&gt;();
      ResultSet rs = null;
      Connection conn = null;
      PreparedStatement pstmt = null;
  
      Twitter twitter = new TwitterFactory().getInstance();
      try {
          User user = twitter.showUser(userName);
          long userID = user.getId();
      } catch (IllegalStateException e1) {
          // TODO Auto-generated catch block
          e1.printStackTrace();
      } catch (TwitterException e1) {
          // TODO Auto-generated catch block
          e1.printStackTrace();
      }
  
      String query = "select userclient.username from twitter_content.userclient where userclient.userid = " +
              "(select follower.followerid from twitter_content.follower where follower.followerid = userclient.userid and follower.userid = ?)";
      System.out.println(query);
  
      String userNames = null;
      String query1 = null;
      try{
          JDBC db = new JDBC();
          conn = db.getConnection();
          pstmt = conn.prepareStatement(query);
          pstmt.setLong(1, userID);
          rs = pstmt.executeQuery();
  
          Properties config = new Properties();
          config.load(new FileInputStream("C:/Users/L31207/Desktop/FYPJ/OpenCalais/MarcusFYPJ/categories.properties"));
          String[][] categories = fetchArrayFromPropFile("content", config);
          HashMap&lt;String,Integer&gt; hashmap = new HashMap&lt;String,Integer&gt;();
          for (String[] mapping : categories)
          {
              hashmap.put(mapping[0], 0);
  
          }
  
          while(rs.next()){
              int id = rs.getInt("followerid");
              userNames = rs.getString("username");
              intArray.add(id);
          }   
  
          ResultSet rs1 = null;
          Connection conn1 = null;
          PreparedStatement pstmt1 = null;
  
              for(int i=0;i&lt;intArray.size();i++){
                  query1 = "Select post.content from twitter_content.post where post.userid = "+intArray.get(i)+"";
                  JDBC db1 = new JDBC();
                  conn1 = db1.getConnection();
                  pstmt1 = conn1.prepareStatement(query1);
                  rs1 = pstmt1.executeQuery();
              }
                  while(rs1.next()){
                      Post post = new Post(rs.getString(userNames), rs.getString("content"), hashmap);
                      System.out.println(rs.getString("content"));
                      postArray.add(post);
                      System.out.println(postArray.size());
                  }
      }
      catch (Exception e) {
          System.err.println(e);
      }
      return postArray;
  }
  </code></pre>