0

I am working on my play app which uses anorm to access my DB. So here goes the part of my application.conf

db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost:3306/bubusik?characterEncoding=UTF-8"
db.default.user=root
db.default.password="*********"

If I remove the ?characterEncoding=UTF-8 part then anything not English language will be as ???????? questions marks in the DB. So I am wondering what exactly this piece of config sets up? Please note that default charset of my DB schema is UTF-8 as well as for all it's tables.

4

1 回答 1

1

这部分配置文件设置 JDBC 驱动程序,它将您的应用程序连接到数据库。db.default.url 用于设置与 MySql 数据库的连接。由于 Play/Scala 在 Java 虚拟机上运行,​​因此您的应用程序以 UTF-16 编码保存字符串。characterEncoding 参数定义数据库期望接收文本字符串的字符集。

因此 ?characterEncoding=UTF-8 通知驱动程序代码,它需要在将 JDBC 请求发送到 MySql 之前将字符串从 UTF-16 映射到 UTF-8。如果目标编码与数据库的编码不匹配,则 JDBC 请求中的字符串格式将使用错误的规则集进行解码。

有关更多详细信息,请参阅:使用字符集和 Unicode

于 2013-11-03T18:05:10.050 回答