在struts+spring+hibernate環境下設定資料庫,要讓資料庫顯示中文,需要修改資料目錄/下的my.ini檔案(我用得是mysql),修改兩處地方如下,紅色字型為要修改的地方
client] port=3306 [mysql] default-character-set=gb2312 # SERVER SECTION # ---------------------------------------------------------------------- # # The following options will be read by the MySQL Server. Make sure that # you have installed the server correctly (see above) so it reads this # file. # [mysqld] # The TCP/IP Port the MySQL Server will listen on port=3306 #Path to installation directory. All paths are usually resolved relative to this. basedir="C:/Program Files/MySQL/MySQL Server 5.0/" #Path to the database root datadir="C:/Program Files/MySQL/MySQL Server 5.0/Data/" # The default character set that will be used when a new schema or table is # created and no character set is defined default-character-set=gb2312 |
記住以下幾點:
1、一定要兩個地方同時修改,否則還會顯示亂碼
2、修改完了以後要記得把原先的資料庫,表重建立立一遍,否則程式會出現問題(具體原因我也不是很清楚啊)。
3、搞定以上兩點後重新啟動以下資料庫伺服器即可。