title: check the manual that corresponds to your MySQL server version for the right syntax to use near '? and password = ?' at line 1
body: <p>I'm having a problem with SQL. this is my code and I don't know why and don't know to fix it. I use Java EE and Eclipse to do this. </p>
  
  <pre><code>public void userLogin(String username,String password) {
  
     Connection conn = null;  
     PreparedStatement ps = null; 
     ResultSet rs = null;
  
     try {        
        conn = JDBCUtilsWithProperties.getConnection();
        String sql = "select * from users where username = ? and password = ?;";
        ps = conn.prepareStatement(sql);
        ps.setString(1,   username);
        ps.setString(2,   password);
        rs = ps.executeQuery(sql);
  
        if(rs.next()) {   
           System.out.println("SUCESS");
        } else {
           System.out.println("FAIL");
        }
  
        } catch (Exception e) {
           // TODO: handle exception
           e.printStackTrace();
        } finally {
           JDBCUtilsWithProperties.release(rs, ps, conn);
        }     
     }
  }
  
  public class JDBCUtilsWithProperties {
  
     private static String driverClass;
     private static String url;
     private static String username;
     private static String password;
  
     private JDBCUtilsWithProperties(){}
  
     static {
        try {
           readConfig();
           Class.forName(driverClass);
        } catch (Exception e) {
           // TODO: handle exception
           e.printStackTrace();
        }
     }
  
     public static void readConfig() {    
        Properties pp = new Properties();
        try { 
           pp.load(new FileInputStream("src//config.properties"));
           driverClass = pp.getProperty("driverClass");
           url = pp.getProperty("url");
           username = pp.getProperty("username");
           password = pp.getProperty("password");
        } catch (Exception e) {
           // TODO: handle exception
        }
      }
  
      public static Connection getConnection() {
         try {
            return DriverManager.getConnection(url,username,password);
         } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }
         return null;
      }
  
      public static Statement createStatement() {
         Connection conn = getConnection();
         Statement stat = null;
         try {
            stat = conn.createStatement();
         } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }
         return  stat;
      }
  
      public static void release(ResultSet rs,Statement stat,Connection conn){
         if(rs != null) {
            try {
               rs.close();
            } catch (Exception e) {
               // TODO: handle exception
               e.printStackTrace();
            }
            rs = null;
          }
          if(stat != null) {
             try {
                stat.close();
             } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
             }
             stat = null;
          }
          if(conn != null) {
             try {
                conn.close();
             } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
             }
             conn = null;
          }
      }
  
      public static void release(Statement stat,Connection conn) {
         if(stat != null){
            try {
               stat.close();
            } catch (Exception e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
            }
            stat = null;
          }
          if(conn != null) {
             try {
                conn.close();
             } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
             }
             conn = null;
          }
      }
  }
  </code></pre>
  
  <p>When run it appears a notification:</p>
  
  <blockquote>
    <p>"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 '? AND password=?' at line 1"</p>
  </blockquote>