龍行天下

            政 博
          隨筆 - 23, 文章 - 0, 評(píng)論 - 12, 引用 - 0
          數(shù)據(jù)加載中……

          hibernate的中文問(wèn)題的解決方案

          系統(tǒng)配置:win2k3 server,jsdk 1.5.0 rc,mysql 4.0.20a,hibernate 2.1.0 ,elcipse 3.0.1
          問(wèn)題描述:在使用hibernate作為數(shù)據(jù)持久層的方案時(shí),照樣會(huì)遇到中文問(wèn)題,具體情況時(shí)插入到數(shù)據(jù)庫(kù)中的漢字顯示為??,顯示數(shù)據(jù)時(shí)漢字為??
          探索: 經(jīng)過(guò)試驗(yàn)發(fā)現(xiàn)與漢字編碼有關(guān)的地方有以下兩處,一個(gè)是數(shù)據(jù)庫(kù)連接url ,一個(gè)是編程時(shí)獲取Configuration 類的實(shí)例的語(yǔ)句的方式。
          方案1:
          ??? * 編程時(shí)獲取Configuration 類的實(shí)例的語(yǔ)句為
          ??? * new Configuration().addClass(xx.class);
          ??? 必須在hibernate.properties文件里數(shù)據(jù)庫(kù)連接url后加上?characterEncoding=gbk&useUnicode=true
          方案2:
          ??? * 編程時(shí)獲取Configuration 類的實(shí)例的語(yǔ)句為
          ??? * new Configuration().configure().
          ??? 在hibernate.cfg.xml文件的<session-factory/>塊中設(shè)置
          ??????? <property name="connection.useUnicode">true</property>
          ??????? <property name="connection.characterEncoding">UTF-8</property>
          ??? 或編程時(shí)寫(xiě):
          ????? Properties extraProperties = new Properties();
          ????? extraProperties.put("hibernate.connection.useUnicode", "true");
          ????? extraProperties.put("hibernate.connection.characterEncoding", "UTF-8");
          ????? myConfiguration.addProperties(extraProperties);

          原來(lái)懷疑與xml頁(yè)面的編碼有關(guān)試了一下,好像不起作用。

          posted on 2006-05-08 14:42 feingto 閱讀(458) 評(píng)論(2)  編輯  收藏 所屬分類: Java Web

          評(píng)論

          # re: hibernate的中文問(wèn)題的解決方案  回復(fù)  更多評(píng)論   

          我也遇到過(guò)這個(gè)問(wèn)題
          2006-05-09 14:00 | necklace

          # re: hibernate的中文問(wèn)題的解決方案  回復(fù)  更多評(píng)論   


          不錯(cuò)哦
          2006-05-28 10:44 | pc
          主站蜘蛛池模板: 秦皇岛市| 新疆| 东莞市| 呼和浩特市| 小金县| 虞城县| 闵行区| 稻城县| 东乡县| 延川县| 莒南县| 江口县| 和平区| 南京市| 四子王旗| 九江市| 磐安县| 青州市| 大安市| 北安市| 崇信县| 阿瓦提县| 漠河县| 阿克陶县| 红原县| 盱眙县| 建水县| 云阳县| 阳信县| 明光市| 汉中市| 本溪市| 临武县| 神池县| 神农架林区| 交口县| 惠东县| 宜良县| 双江| 互助| 黎城县|