title: JSP encoding while inserting non-English text in MySQL database
body: <p>I am using Ajax call to insert Indian characters in MySQL database. I am facing an UTF-8 encoding problem in between flow of my application.</p>
  
  <p>When I am inserting the non-English characters directly by JDBC (not using an Ajax call), then it's showing "????" in the database.</p>
  
  <p>When I include</p>
  
  <pre><code>response.setCharacterEncoding("UTF-8");
  request.setCharacterEncoding("UTF-8");
  response.setContentType("text/html;charset=UTF-8");
  </code></pre>
  
  <p>in my JSP file, then I receive the following in my database (question marks instead of non-English characters):</p>
  
  <blockquote>
    <p>????????</p>
  </blockquote>
  
  <p>When I do not include above lines it shows me junk character like this in database:</p>
  
  <blockquote>
    <p>àª®à«?àª?àªªà«?àª·à«?àª</p>
  </blockquote>
  
  <p>Whereas the actual value is</p>
  
  <blockquote>
    <p>મખપષ</p>
  </blockquote>
  
  <p>So the actual problem lies in or after sending insert request to MySQL command in JSP through JDBC jdbc connector.</p>
  
  <p>I have included following tags in all my JSP files to ensure character encoding:</p>
  
  <pre><code>&lt;%@page contentType="text/html"%&gt;
  &lt;%@page pageEncoding="UTF-8"%&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8;charset=UTF-8"&gt;
  </code></pre>
  
  <p>I checked MySQL tables are Unicode enabled and I am able to enter correctly non English text through terminal.</p>
  
  <p>How is this problem caused and how can I solve it?</p>
  
  <p>Now, i am able to write using a insert statement only....but when i mix some queries and insert statement then... my application return me following error:
  Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='
  following are my database variables:</p>
  
  <pre><code>| Variable_name            | Value                      |
  +--------------------------+----------------------------+
  | character_set_client     | utf8                       |
  | character_set_connection | utf8                       |
  | character_set_database   | utf8                       |
  | character_set_filesystem | binary                     |
  | character_set_results    | utf8                       |
  | character_set_server     | utf8                       |
  | character_set_system     | utf8                       |
  | character_sets_dir       | /usr/share/mysql/charsets/ |
  | collation_connection     | utf8_general_ci            |
  | collation_database       | utf8_general_ci            |
  | collation_server         | utf8_general_ci            |
  | completion_type          | 0                          |
  | concurrent_insert        | 1                          |
  | connect_timeout          | 10                         |
  </code></pre>