私はMysqlの文字エンコーディングについて混乱しています。 私はこのようにHibernateでconnection.urlを設定:JDBC MySQL文字エンコーディング:useUnicodeはなぜ必要ですか?
<property name="connection.url">jdbc:mysql://localhost:3306/Bag</property>
<property name="hbm2ddl.auto">update</property>
エンティティクラスは次のとおりです。
:@Entity
@Table(name = "notification")
public class Notification {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private long id;
@Column(name = "username", unique = true,nullable = false, length = 64)
private String username;
@Column(name = "title", nullable = false, length = 64)
private String title;
@Column(name = "message", nullable = false, length = 1000)
private String message;
@Column(name = "uri", nullable = true, length = 256)
private String uri;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
}
が、私は '通知' と呼ばれるMySQLでテーブルを作成してい
notification | CREATE TABLE `notification` (
`id` bigint(20) NOT NULL,
`message` longtext NOT NULL,
`title` varchar(64) NOT NULL,
`uri` longtext,
`username` varchar(64) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
中国語の文字列を挿入するとうまく動作しません。
mysql> select * from notification;
+----+---------------------------------+--------------------+------+
| id | message | title | uri |username |
+----+---------------------------------+--------------------+--------
| 1 | ??,???????? | ???? |/post/toPluto | pluto |
私はにconnection.urlを変更することで問題を解決しています
<property name="connection.url">jdbc:mysql://localhost:3306/Bag?useUnicode=true&characterEncoding=UTF-8</property>
誰かが私に理由を言うことができる私は、その理由を知らないのですか?
これは、これは中国の文字列の六角ある
Variable_name Value
| character_set_client | utf8
|
| character_set_connection | utf8
|
| character_set_database | utf8
| character_set_filesystem | binary
|
| character_set_results | utf8
|
| character_set_server | latin1
|
| character_set_system | utf8
|
| character_sets_dir | /usr/local/mysql-5.7.11-
osx10.9x86_64/share/charsets/ |
MySQLのcharacter_setは次のとおりです。
mysql> select hex(message) from notification;
+----------------------------------------------------------------+
| hex(message) |
+----------------------------------------------------------------+
| 3F3F2C3F3F3F3F3F3F3F3F