title: SQL syntax error: "com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax;"
body: <p>Trying to establish a JDBC connection in an android studio app, and I am getting the following error:</p>
  <pre><code>2020-07-06 13:16:55.229 12576-12664/com.example.mmi W/System.err: 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 'and USER PASSWORD=' at line 1
  2020-07-06 13:16:55.230 12576-12664/com.example.mmi W/System.err:     at java.lang.reflect.Constructor.newInstance0(Native Method)
  2020-07-06 13:16:55.230 12576-12664/com.example.mmi W/System.err:     at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
  2020-07-06 13:16:55.230 12576-12664/com.example.mmi W/System.err:     at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
  2020-07-06 13:16:55.230 12576-12664/com.example.mmi W/System.err:     at com.mysql.jdbc.Util.getInstance(Util.java:408)
  2020-07-06 13:16:55.230 12576-12664/com.example.mmi W/System.err:     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944)
  2020-07-06 13:16:55.230 12576-12664/com.example.mmi W/System.err:     at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3976)
  2020-07-06 13:16:55.230 12576-12664/com.example.mmi W/System.err:     at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3912)
  2020-07-06 13:16:55.230 12576-12664/com.example.mmi W/System.err:     at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530)
  2020-07-06 13:16:55.230 12576-12664/com.example.mmi W/System.err:     at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683)
  2020-07-06 13:16:55.230 12576-12664/com.example.mmi W/System.err:     at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2482)
  2020-07-06 13:16:55.230 12576-12664/com.example.mmi W/System.err:     at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2440)
  2020-07-06 13:16:55.230 12576-12664/com.example.mmi W/System.err:     at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1381)
  2020-07-06 13:16:55.230 12576-12664/com.example.mmi W/System.err:     at com.example.mmi.MainActivity$MyTask.doInBackground(MainActivity.java:69)
  2020-07-06 13:16:55.230 12576-12664/com.example.mmi W/System.err:     at com.example.mmi.MainActivity$MyTask.doInBackground(MainActivity.java:48)
  2020-07-06 13:16:55.230 12576-12664/com.example.mmi W/System.err:     at android.os.AsyncTask$3.call(AsyncTask.java:378)
  2020-07-06 13:16:55.230 12576-12664/com.example.mmi W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
  2020-07-06 13:16:55.230 12576-12664/com.example.mmi W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:289)
  2020-07-06 13:16:55.230 12576-12664/com.example.mmi W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
  2020-07-06 13:16:55.230 12576-12664/com.example.mmi W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
  2020-07-06 13:16:55.230 12576-12664/com.example.mmi W/System.err:     at java.lang.Thread.run(Thread.java:919)
  </code></pre>
  <p>Here is my code:</p>
  <pre><code>Connection con = DBUtility.connect();
  Statement st = con.createStatement();
  ResultSet rs = st.executeQuery(&quot;SELECT * FROM mmi_userinfo where USERNAME='&quot;+ user + &quot;' and USER PASSWORD='&quot; + pass + &quot;'&quot;);
  </code></pre>
  <p>Here is the DBUtility class code:</p>
  <pre><code>public class DBUtility
  {
      public static Connection connect() throws ClassNotFoundException, SQLException {
          Connection con;
  
          //Class.forName(&quot;com.mysql.cj.jdbc.Driver&quot;);
          con = DriverManager.getConnection(&quot;jdbc:mysql://192.168.1.235:3306/mmi?useSSL=false&quot;,&quot;loginuser&quot;,&quot;loginpass&quot;);
  
          return con;
      }
  }
  </code></pre>