I am using Glassfish 4.0, JSF 2.2.5, MySQL 5.5 and J Conn 5.1.29. When I enter some Cyrillic letters in a form, they are saved as "ÑдÑдÑÑдÑ" in the database. I have also noticed that if the validation fails in the form, the existing Cyrillic letters in the form are modified to "ÑдÑдÑÑдÑ".
It is working right if I saved them through MySQL Workbench, and they are displayed fine on the web page.
The JSF page is set to UFT-8.
MySQL:
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
The problem was solved when I added the following to the glassfish-web.xml
<parameter-encoding default-charset=”UTF-8″/>
Related
This question already has answers here:
Problems reading/writing UTF-8 data in MySQL from Java using JDBC connector 5.1
(3 answers)
Closed 6 years ago.
I made a Dynamic Web Project in Eclipse, using jsp's, servlets, an encoding filter and MySQL as the place to store my db tables.
Whenever I submit a form with Korean/Chinese/Japanese letters it shows up as ???? in the database table.
The problem seems to be with the actual code where I make the connection and execute the query. I don't think the insert statement is encoded in UTF-8, which is why it shows up as question marks.
Is there a file or piece of code I need to modify regarding the JDBC driver in order to store UTF-8 characters in my database?
I have already made sure my jsp files have UTF-8 charset and encoding in the page and meta tags, and put this in my servlets:
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
Its realy simple to add multi-language in MySQL Workbench, if you got MySQL Workbench, just go to the console, click your database, and look for collation, set it to utf8_general_ci, after that all your data will show correctly.
You can also do this by executing a query : Alter TABLE TABLE_NAME_HERE
CHARACTER SET utf8 COLLATE utf8_unicode_ci;
I am dealing with a Brazilian customer where the data is in Portuguese language.
My application is responsible to read the data through web-service calls and store it in our database. The issue that I am currently facing is the Portuguese characters are not getting identified as it is and is stored in my database as a special character.
I am using MySQL database with all tables configured as collation UTF-8. I tried manually inserting Portuguese character into my database and it worked. So I am suspecting its java who is converting the Portuguese characters into special character.
Also, my application is using Hibernate for database operations.
I am able to get the character as I see in logs and the issue reside while trying to store that data in database.
Eg: Original characters: Gerãt
Database characters: Gerãt
What configurations or setting or changes I need to do to my database so that I can capture the data in Portuguese language as it is?
It may not be database issue, but an application configuration issue.
Few pointers to help :
Check the webservice implementation if it can accept Portugese chars
Check the encoding in your web container. For example Tomcat
Add logs to find out where the Portugese chars are lost.
Hope it helps.
Try changing your hibernate configuration to:
<hibernate-configuration>
<session-factory>
<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">UTF-8</property>
<property name="connection.charSet">UTF-8</property>
If that doesn't work, try adding UTF-8 to your characterEncoding in your JDBC url.
Also, this question might help you: Cannot insert non latin symbols in MySQL
This worked in my case:
Add environment variable JAVA_TOOL_OPTIONS instead of _JAVA_OPTIONS with value as
-Dfile.encoding=UTF8
I have a setup liferay6.06 version in my ubuntu system, its working fine, I am using the mysql database,before changing database password its working fine, after that I have changed database password,i have updated the changed password in portal.properties,while starting the tomcat server it is not connecting to the database and server is started. while accessing url iam getting 404 error. what are the places i need to update the changed password in liferay 6.06?
You need to create portal-ext.properties file inside classes folder and add following lines.
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=
jdbc.default.password=
HTH
I have big problem in my web application using JSF and EclipseLink JPA to MySQL database.
When I read data from database JSF reads and writes my charachters in UTF-8 OK. but in database characters are bad.
f.e.: input characters: "żźćółzxcv", written in database: "?????zxcv".
But if I manually write data to database, for example: "żźćółzxcv", then reading in JSF is perfect.
I tried everything from here: Unicode input retrieved via PrimeFaces input components become corrupted
And I discovered that encoding in JSF is fine, but the problem is in java, becouse if I set manually
current.setUwagiZ("żźćóżźćłąśóżźćł TE");
getFacade().edit(current);
in database record is wrong: ???ó??????ó???? TE
I have set characterEncoding and useUnicode in JDBC Resource. Also when execute commands by some tools in NetBeans encoding is OK and data in MySQL are in UTF-8, so connections seems fine.
So the problem is java, but I completely don't know how to solve this :(
Question marks can occur when the messenger itself is aware about the character encoding used in the both sides of the transport. That's the difference with Mojibake whereby it's not the messenger's fault, but the producer's and/or consumer's fault.
In an average web application with a database backend, there are only 2 places where this can happen: communication with the DB and communication with the HTTP client. You've already excluded the HTTP part, so left behind the DB part.
The messenger in the DB part is the JDBC driver. You need to tell the JDBC driver to use UTF-8. MySQL JDBC driver is known to use by default the client platform default encoding, which is in your particular case apparently not UTF-8.
Add the following 2 properties to the JDBC connection:
useUnicode=true
characterEncoding=UTF-8
It's unclear how you've configured the JDBC connection, but if it's "plain vanilla" JDBC, then specify them as query string in JDBC URL:
jdbc:mysql://localhost:3306/db_name?useUnicode=true&characterEncoding=UTF-8
Or if it's a container-specific datasource config, then specify them as separate connection properties, exactly the same way as you specify the username and password.
See also:
Unicode - How to get the characters right?
I am getting this string which contains this substring gratuit.AFLĂ MAI MULTEDe from webservice. when i save this in data base in my local(windows) works fine but when i try to save on server when it is deployed on linux i get following error:
Incorrect string value: '\xC4\x82 MAI...' for column 'description' at row 1
I am using hibernate 3.3 with mysql 5.5 (both windows and linux) and database usage default encoding (latin1).
I have tried setting -Dfile.encoding=UTF8 in JAVA_OPT but not worked, i think its this is os related problem.
Any suggestion?
(In general nowadays I would do all in UTF-8.) There is a long pipeline of points where encoding can be set. From the web service you get probably XML in UTF-8. That is automatically read correctly, as XML handles the encoding strict.
On database level there is the database and table and field with a default and explicit encoding. Furthermore the connection url should be parametrised to the correct encoding.
The error message shows the UTF-8 bytes for that accented A and I guess it is not available in Latin1.
For MySQL the connection string could look like:
jdbc:mysql://localhost/MYDB?useUnicode=true&characterEncoding=UTF-8