title: Java - to - sql statement, variables in Insert into vs setString
body: <p>What is the difference between these two statements, do they both work the same way, or does the first one work at all? Can I use variables after "Insert into"?</p>
  
  <pre><code>stmt = conn.prepareStatement("INSERT INTO treatment(CPR,Treatment,ID,TreatedOn) "+
  "VALUES("+Cpr+Id+date.toString());
  </code></pre>
  
  <p>Where <code>id</code>, <code>cpr</code> are a <code>string</code>,<code>int</code> or other variable, bin my case it is a <code>string</code>,</p>
  
  <pre><code>PreparedStatement insertStatement;
  
          insertStatement = connection.prepareStatement("INSERT INTO sep2.movies(title,length) "
                  + "VALUES (?,?,?)");
          insertStatement.setString(1, Title);
          insertStatement.setInt(2, movie.getLength());
  </code></pre>
  
  <p>where <code>Title</code> is a string and <code>getLength</code> returns an <code>int</code>.</p>
  
  <p>Which one of these should I use ?</p>
  
  <p>I understand what <code>setString</code> does but do I have to use it?</p>
  
  <p>Also I am inserting only elementary/non-object data types into <code>Treatment</code>. Does it make a difference? (I am using <em>postgres</em> if that matters)</p>