I wrote a JSP code that needs to run some mysql INSERT queries that contains non-English chars (Persian). I run two types of queries first one is static application installation queries and second one is user inputs. After execution of both of queries non-English chars are imported as “?” as I check them in application itself and phpMyAdmin!
I tried to execute these queries after connection but I didn’t help:
SET NAMES utf8
SET CHARACTER SET utf8
SET SESSION collation_connection = 'utf8_general_ci'
What’s the problem ? How can I fix it?
So, the database (or more specifically, the JDBC driver) is not using UTF-8 during
INSERT.Usually the database’s JDBC driver should be smart enough to use the database and/or table specified encoding for storing the data. But in some cases you have to specify the character encoding in the connection string as well. This is true in case of MySQL JDBC driver because it does not use the database-specified encoding, but the client-specified encoding. How to configure it should already be answered in the JDBC driver documentation. In for example MySQL you can read it here:
That said and unrelated to the problem, you should in fact try to avoid raw Java code in a JSP file. It would only lead to another kinds of problems in the future.