How to convert string encoding?

43 views
Skip to first unread message

david.and...@gmail.com

unread,
Jul 20, 2017, 5:16:38 AM7/20/17
to jOOQ User Group
Hi,

I have a mysql database where all of its content are encoded as latin1, when I fetch the data it tries to convert to utf8 and it messes up everything.
The best way we got to solve this was with this ugly line of code:


content = Field(

"
convert(cast(convert("
+ TABLE_NAME + ".content using latin1) as binary) using utf8)",
String.class
So, is there a better way to do this?
 Thanks, David

Lukas Eder

unread,
Jul 20, 2017, 5:20:53 AM7/20/17
to jooq...@googlegroups.com
jOOQ just passes Strings through to JDBC and fetches them from JDBC without interfering with encoding. So, I suspect this may be related to the JDBC driver settings. MySQL knows JDBC driver properties such as:
  • characterEncoding
  • characterSetResults
  • connectionCollation
More information here:

Does that help?

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel

unread,
Oct 29, 2017, 8:28:34 PM10/29/17
to jOOQ User Group
Hi Lukas,

I have a similar issue, and it looks like a JDBC bug:

The 6.0.5 release log claims they've solved the issue, but the problem still applies to normal VARCHAR columns.
I tried converting the table from latin1 to utf8mb4, changing the characterSetResults to latin1, then utf8, but nothing works.

The only thing that works is using ResultSet.getBytes instead of getString:

  new String(res.getBytes("columnName"), "UTF-8")

Is there any way I can get JOOQ to use getBytest instead of getString?

Thanks,
Daniel


To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.

Lukas Eder

unread,
Oct 30, 2017, 3:50:14 AM10/30/17
to jooq...@googlegroups.com
Hi Daniel,

Thanks for your message. You can easily override jOOQ's DefaultBinding by implementing your own data type Binding, and by using the code generator to bind that binding to all the relevant columns:

Do note that the encoding used by client / server depends on a variety of settings, including the collation of the server, of the individual column, of the driver (you can override things in the JDBC connection string) and on the JVM.

Hope this helps,
Lukas

To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages