简体   繁体   中英

How does JDBC connection character-encoding works?

In JDBC url you specify the character encoding .

ex:

jdbc:mysql://host:3306/db?characterEncoding=UTF8

.

jdbc:teradata://host/DBS_PORT=1025,DATABASE=Orders,CHARSET=UTF8

I am trying to understand how this actually works.

Does this mean that the client specifically asks the server in which character-encoding it wants data?

If actual data is saved in different character encoding in DB (say Shift_JIS), does the DB server perform the encoding conversion before sending data to the client? (in this example, from SJIS to UTF-8 ?)

This is not directly related to JDBC, but it is a specific implementation detail for individual JDBC drivers. Not all drivers/databases allow you to specify a connection character set. This could be because their protocol always uses a specific character set, or the encoding is fixed per column and communicated together with the data. And if a driver does have such a property, its effects will vary per driver/database system and maybe even per specific database, table or even column.

It is not really possible to generalize exactly what such a setting does over drivers.


I already find it hard enough to describe the exact effects (and edge cases) of the connection character set for the JDBC driver that I maintain..., let alone consider/investigate that for other drivers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM