title: How to concatenate sql query in java?
body: <p>I'm beginning to learn sql and java and I have a problem. </p>
  
  <p>The logic for the code is:</p>
  
  <p>The first part of the sql statement should be "a.stdn_code_ts" and as more elements (in this case student code) are included, I need to concatenate with and OR-Statement.</p>
  
  <p>student codes could be a single value or a range, say for example: '567777' is valid as well as '567777-876677'.</p>
  
  <p>If it is single value, just add "=" then the student code. In the example if the user entered '567777' then the query should be something like "a.stdnt_code_ts = '567777'"</p>
  
  <p>If it is a range, add the first student code then "BETWEEN" second code. I.e.: if the user entered '567777-876677', the query should be "a.stdnt_code_ts BETWEEN '567777' AND '876677'".</p>
  
  <p>and as I mentioned above, if there are 2 or more student codes the query should be concatenated with an "OR a.stdnt_code_ts" then checks again if it is a single value or a range.</p>
  
  <p>I already have this code and got stuck:</p>
  
  <pre><code>private void formatStudentCode(Connection connection) throws Exception {
      studentCode = "a.stdnt_code_ts ";
  
      for(int i=0; i &lt; stdntCode.size(); i++) {
          if (stdntCode.get(i).indexOf("-")==-1) {
              studentCode += "= '" + stdntCode.get(i) + "'";
          }
          else {
              String [] range=stdntCode.get(i).split("-");
              studentCode += "BETWEEN '" + range[0] + "' AND '" + range[1] + 
              "'";
          }
      }
  }
  </code></pre>