title: Prepared statements with MySQL?
body: <p>I am having some trouble with, what I believe to by syntax, for prepared statements.  </p>
  
  <p>I have the following code</p>
  
  <pre><code>String query2="SELECT lname FROM school_student WHERE sid = ? ORDER BY sid;";
  
  PreparedStatement ps = cn.prepareStatement(query2);
  ps.setInt(1, 3);
  ResultSet rs = ps.executeQuery(query2);
  </code></pre>
  
  <p>The problem I am having is that I am getting this error message:</p>
  
  <blockquote>
    <p><code>com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? ORDER BY sid' at line 1</code></p>
  </blockquote>
  
  <p>However, when I substitute the "?" in my query for a 3, the query works fine with no error and gives me what I want.  There seems to be something wrong with how I am setting the value of the "?" in my query?  Am I using the wrong syntax?</p>