Jason Bourne
Jason Bourne

Reputation: 786

Issue with special characters in Glassfish/Java EE6/MySQL

I am working on a small application that stores data in a MySQL database. The data is various fields, some are in Turkish, Russian or Arabic. When inserting new record it is saved in the database in "??????" and other wired chars.

The architecture of the application is like this

JSP Form -> Servlet -> EJB -> JPA(EclipseLink) -> Glassfish (JDBC Pool <-> JDBC Resource)->MySQL

I already :

But the issue didnt get solved

Upvotes: 3

Views: 672

Answers (2)

Jason Bourne
Jason Bourne

Reputation: 786

I found the solution for this issue, before dealing with the request paramters, just insert:

request.setCharacterEncoding("UTF-8");

And every thing will be ok

Link where I found the solution

Upvotes: 1

watery
watery

Reputation: 5487

I'm able to see only one source of trouble (maybe you omitted it in your question): I don't see the source encoding being considered.
From the JSP Form the user fills, you should somehow get the character set the data was encoded in; then, in the Servler or EJB you convert that data in your destinarion character set (utf-8) before storing it in the database (Java offers some API for this task, but I never used them directly so I can't give you any example).

I don't know about the parameters you added to the JDBC url, so I can't comment on them.

Upvotes: 0

Related Questions