| Bug #120096 | MysqlConnector/Java Connection Url CharacterEncoding bug | ||
|---|---|---|---|
| Submitted: | 18 Mar 8:50 | Modified: | 25 Mar 12:38 |
| Reporter: | we Black | Email Updates: | |
| Status: | Verified | Impact on me: | |
| Category: | Connector / J | Severity: | S3 (Non-critical) |
| Version: | 8.x-9.x | OS: | Windows (Windows 11 家庭中文版) |
| Assigned to: | Filipe Silva | CPU Architecture: | x86 (12th Gen Intel(R) Core(TM) i7-12700H (2.30 GHz)) |
| Tags: | character_encoding, jdbc4.0, ResultSet, URL | ||
[25 Mar 12:38]
Filipe Silva
Thank you for your interest on MySQL Connector/J and for taking the time to report this issue. Verified as described.
[22 Apr 21:40]
OCA Admin
Contribution submitted via Github - Fixed bug #120096 MysqlConnector/Java Connection Url CharacterEncoding bug (*) Contribution by Rahman Rejepov (Github Rahman2001, mysql-connector-j/pull/123#issuecomment-4295054069): I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it. On Wed, Apr 22, 2026, 04:55 mysql-oca-bot ***@***.***> wrote: > *mysql-oca-bot* left a comment (mysql/mysql-connector-j#123) > <https://github.com/mysql/mysql-connector-j/pull/123?email_source=notifications&email_token...> > > Hi, thank you for your contribution. Please confirm this code is submitted > under the terms of the OCA (Oracle''s Contribution Agreement) you have > previously signed by cutting and pasting the following text as a comment: > "I confirm the code being submitted is offered under the terms of the OCA, > and that I am authorized to contribute it." > Thanks > > — > Reply to this email directly, view it on GitHub > <https://github.com/mysql/mysql-connector-j/pull/123?email_source=notifications&email_token...>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/ARUTEP65O3GFQDF5ZGRQ6H34XAQ7RAVCNFSM6AAA...> > . > You are receiving this because you authored the thread.Message ID: > ***@***.***> >
Contribution: git_patch_3564362436.txt (text/plain), 2.56 KiB.

Description: spring: datasource: url: jdbc:aisino:mysql://172.19.64.72:13306/test_hiber?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai I uesed the characterEncoding=utf-8 in the connection url, and I used result.getNString() method to get a String, I got an exception. The exception is java.sql.SQLException: Can not call getNString() when field's charset isn't UTF-8 at com.mysql.cj.jdbc.result.ResultSetImpl.getNString(ResultSetImpl.java:1090) ~[mysql-connector-j-9.6.0.jar:9.6.0] .But I changed the characterEncoding=utf-8 to characterEncoding=UTF-8 is ok, it can work. How to repeat: Change characterEncoding=UTF-8 to characterEncoding=utf-8 or add the configuration to your connection url if you don't have. Suggested fix: I think the if statement "if (fieldEncoding == null || !fieldEncoding.equals("UTF-8"))" in the mysql-connector-j-9.6.0.jar/com.mysql.cj.jdbc.result.ResultSetImpl.class should have convert to the same case to compare.