[2.0] Ebean UTF-8 support for MySQL?

1,003 views
Skip to first unread message

Chris B.

unread,
Mar 24, 2012, 12:04:19 AM3/24/12
to play-fr...@googlegroups.com

I am using MySQL database. The non-english characters can be stored and pulled from database without a problem. But when saving a record using Ebean, all non-english characters were saved as "???" into the MySQL database.

My code updating the record are similar to the computer-database sample code as shown below. Is there a Play/Ebean setting to force using UTF-8 in the Play/Ebean calls such as computerForm.get().update(id) ?

I noticed that the computer-database sample app can support UTF-8 when updatign computer name while using H2 database. Looks like this is database specific. But I have created a UTF-8 database in MySQL. And I can save non-English chars into the database using a client tool. So, I think this is not MySQL's fault.


/**
     * Handle the 'edit form' submission
     *
     * @param id Id of the computer to edit
     */
    public static Result update(Long id) {
        Form<Computer> computerForm = form(Computer.class).bindFromRequest();
        if(computerForm.hasErrors()) {
            return badRequest(editForm.render(id, computerForm));
        }
        computerForm.get().update(id);
        flash("success", "Computer " + computerForm.get().name + " has been updated");
        return GO_HOME;
    }

Chris B.

unread,
Mar 26, 2012, 12:09:34 AM3/26/12
to play-fr...@googlegroups.com
Anyone can help on this? Unicode characters can not be saved into database. I am stuck here.

Guillaume Bort

unread,
Mar 26, 2012, 5:16:11 PM3/26/12
to play-fr...@googlegroups.com
You probably need to specify UTF-8 for the JDBC connection. Check the
MySQL JDBC driver documentation.

On Mon, Mar 26, 2012 at 6:09 AM, Chris B. <chri...@gmail.com> wrote:
> Anyone can help on this? Unicode characters can not be saved into database.
> I am stuck here.
>

> --
> You received this message because you are subscribed to the Google Groups
> "play-framework" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/play-framework/-/KmGTbrC9z_MJ.
>
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to
> play-framewor...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/play-framework?hl=en.

--
Guillaume Bort

Anton Bessonov

unread,
Mar 26, 2012, 5:39:36 PM3/26/12
to play-fr...@googlegroups.com
For JDBC try:
jdbc:mysql://localhost/db?useUnicode=yes&characterEncoding=UTF-8

Plain SQL:
SET NAMES 'utf8';
SET CHARACTER SET utf8;
--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/gOk45l5rhB8J.

To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.


-- 
Oracle Certified Expert, Enterprise JavaBeans Developer
Oracle Certified Professional, Java SE 6 Programmer
Professional Scrum Master

biesior

unread,
Mar 26, 2012, 5:40:29 PM3/26/12
to play-fr...@googlegroups.com
+2 for this answer:

+1 for Guillaume's suggest (thanx, I was looking for this for some time, it works for me now)
+1 for placing this in documentation... someday :)

correct config is:

db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/some_db?characterEncoding=UTF-8"
db.default.user=some_user
db.default.password=some_pass


W dniu poniedziałek, 26 marca 2012, 23:16:11 UTC+2 użytkownik Guillaume Bort napisał:
You probably need to specify UTF-8 for the JDBC connection. Check the
MySQL JDBC driver documentation.

Greetings, Marcus

Chris B.

unread,
Mar 26, 2012, 10:40:19 PM3/26/12
to play-fr...@googlegroups.com
?characterEncoding=UTF-8 did the trick. Many thanks.
+1 for placing this in documentation...

Mikhail Navrotskiy

unread,
Dec 14, 2013, 2:31:16 AM12/14/13
to play-fr...@googlegroups.com, exe...@googlemail.com
For Russian Language this is really good idea!

Many thanks!

вторник, 27 марта 2012 г., 1:39:36 UTC+4 пользователь Anton Bessonov написал:
Reply all
Reply to author
Forward
0 new messages