---
title: "J2EE中Unicode的配置"
author: "cristal"
date: "2009-10-07T21:14:09Z"
tags: ["Apache", "Hibernate", "JDBC", "MySQL", "Tomcat"]
slug: "j2ee-unicode"
draft: false
lastmod: "2009-10-08T18:16:37Z"
id: 482679
url: "https://cristal.iteye.com/blog/482679"
---

数据库使用的是MySQL，Container使用的是Tomcat，为支持Unicode，作如下配置:

1\. MySQL使用Unicode创建数据库:

CREATE DATABASE foo CHARACTER SET utf8 COLLATE utf8\_bin;

对于MySQL而言\_bin表示使用binary存储数据，\_cs表示区分大小写，\_ci表示不区分大小写

2\. Hibernate的配置：

hibernate.connection.url=jdbc:mysql://localhost:3306/foo?useUnicode=true&characterEncoding=UTF-8

3\. Tomcat的配置

&lt;Connector port="8080" URIEncoding="UTF-8" /&gt;

如果使用mod\_jk来连接apache和tomcat，则还需配置：

&lt;Connector port="8009" protocol="AJP/1.3" URIEncoding="UTF-8"/&gt;