在做struts向mysql插入中文記錄時出現 Data too long for column 'name' at row 1 異常,但是插入英文就沒問題,google了下,總結出下面方法,保證你不會再出錯!
1,mysql的編碼設置為 utf8 格式,可以從開始菜單那圖形化配置,或者直接進入安裝目錄配置my.ini
2,在java連接數據庫時這樣寫:
String url ="jdbc:mysql://localhost/sales?user=root&password=riskfitfeng&useUnicode=true&characterEncoding=utf-8";
3,數據庫的編碼為 utf8
4,數據庫表編碼為 utf8
5,數據庫字段編碼為 utf8
6,jsp頁面中編碼為 utf-8
ref:
http://www.programfan.com/club/showpost.asp?id=19359
頁面顯示中文亂碼的話可以參考這里:
http://hi.baidu.com/lovekaili/blog/item/31830e01c94a2cd3267fb503.html (我很早寫的blog)
posted on 2009-05-19 15:48
fl1429 閱讀(3603)
評論(0) 編輯 收藏 所屬分類:
Mysql/Sqlserver/Oracle