title: SQL query not executing in java application
body: <p>I'm using JDBC for the first time and having a tough time at it. This is a code snippet that is giving me error:</p>
  
  <pre><code>//STEP 4: Execute a query
  System.out.println("Creating statement...");
  String sql;
  sql = "SELECT * FROM user where username=? and password=?";
  stmt = conn.prepareStatement(sql);
  //Bind values into the parameters.
  stmt.setString(1, value1);  // This would set username
  stmt.setString(2, value2); // This would set password
  ResultSet rs = stmt.executeQuery(sql);
  </code></pre>
  
  <p>I'm getting the following error in NetBeans:</p>
  
  <blockquote>
    <p>"<code>jdbc.exceptions.jdbc4.MySQLSyntaxErrorException</code>: 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 '<code>? and password=?</code>' at line 1"</p>
  </blockquote>
  
  <p>There is a long list after this but I think this is the thing which is causing me problems. What am I doing wrong? </p>