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?
Related
We have a Java based desktop Application, that does two parts jdbc logon, one is for creating a connection with Oracle DB, this let user to execute queries and stored procedures, and second jdbc logon happens if user tries to generate/print Crystal report. For this crystal java interface we are using crjava-runtime_12.2.223.zip libraries from SAP community. Now the strange thing is on all of our developers machine, we don't face any error of invalid connection string format, but this error is coming only at one of the production user's account. He is able to logon to the application successfully i.e. first jdbc connection but when he is trying to establish the connection with crystal interface he is facing this error of Logon Error:IO Error: Invalid connection string format, a valid format is: "host:port:sid"
We have tried resolving this by following jdbc URL formats(read lots of Java JDBC questions- How to connect to Oracle using jdbc formats) but he is getting the same error always while establishing connection with Crystal Interface. (SID and service name for the user is same as abcprod)
jdbc:oracle:thin:#abc-db.abchosting.local:1521:abcprod
jdbc:oracle:thin:#//abc-db.abchosting.local:1521/abcprod
jdbc:oracle:thin:#abcprod(Using TNSFILE)
jdbc:oracle:thin:#abc-db.abchosting.local:1521/abcprod
User is on oracle version 12c, there are two other users on that same DB, they are not facing this error at all. Can anybody suggest what should we check, Is this application issue(code level) or Oracle grants/permission issue? I have asked DBA to compare the grants for all these three users but he is saying all grants are same for them. Any hints or suggestions?
This issue is not related with Oracle's JDBC library, this is related with SAP Crystal Report's library for java, because if we are making connection with oracle's JDBC library it works fine, my first statement says: two parts JDBC logon, first with plain oracle's JDBC library which works fine, second part with crystal's library, same connection string/URL which was used in first part, when trying establishing connection it throws error but this error is specific to only one user rest of the other users in production don't face this error.
We are able to fix this issue. Although we have tried plenty of solutions for this, the issue is only coming with the Users having special characters in their password like if they have setup their password like this: Abcd#12345, this '#' character is causing this error. Removing this character resolved this issue, Also it is recommended not to use such characters like '#', '.' in your password.
https://asktom.oracle.com/pls/apex/f?p=100:11:::NO:RP:P11_QUESTION_ID:9533940800346284735
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 deployed an existing Maven project in my Tomcat Server on Windows7 environment. I'm using tomcat7 , spring-security-core 3.1.0 .
However, everytime I'm logging in my webapp, I received an error
java.lang.IllegalArgumentException: Non-hex character in input
The code is working perfectly fine in Linux environment. So I was thinking it's because I'm using windows7 in my local environment. When I look into the internet I saw that's it's a encoding issue between linux and windows.
I tried setting up
JAVA_TOOL_OPTIONS -Dfile.encoding=UTF8
but haven't succeeded. Please help me out. Thanks in advance!
Most likely, when you login, events happen is such order:
Spring selects an entity from DB by username.
Spring must check inputted password for match with stored encoded password.
To check for a match, Spring uses PasswordEncoder, which you have most likely configured.
Your password encoder expects that stored encoded password is a hexidecimal char sequence (previously encoded by this PasswordEncoder). Thus, it tries to decode CharSequence into byte[], but fails (source).
The solution is to persist users with previously encoded password, e.g. by BCryptPasswordEncoder.
Answer Alex Derkach is right for me!
In my case i have DB with straight store password(develop) looks like User=roor, psw=root.
So when i comment(delete) .passwordEncoder(new StandardPasswordEncoder("53c433t")); ! its work
!!But is wrong, password must be stored in encrypted form!!!
A possible reason for this is mixing password encoders. There're different implementations of PasswordEncoder. And, for example, if you use SymmetricPasswordEncoder for encoding and StandardPasswordEncoder for decoding you may get this exception.
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 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