title: Escape single quotes in JDBC (getting error: You have an error in your SQL syntax ...)
body: <p>I'm trying to insert data into mysql using jdbc. I have something like this:</p>
  
  <pre><code>    Connection conn = DriverManager.getConnection(urlDB, userDB, passwordDB);
  
      String postTitle = "Post title";
      String postContent = "A Linux's distributions";
  
      String sql = "INSERT INTO posts VALUES ( '"+postTitle+"', '"+postContent+"')";          
      PreparedStatement statement = conn.prepareStatement(sql);
      statement.executeUpdate();
      conn.close();
  </code></pre>
  
  <p>But I'm getting an error:</p>
  
  <pre><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 's
  </code></pre>
  
  <p>As far as I know the prepareStatement method should escape single quotes (Мaybe I'm wrong). I'll be glad for any suggestions.</p>