解決hibernate+mysql寫(xiě)入數(shù)據(jù)庫(kù)亂碼
更新時(shí)間:2009年07月13日 21:33:23 作者:
初次沒(méi)習(xí)hibernate,其中遇到問(wèn)題在網(wǎng)上找的答案與大家共同分享!
hibernate.cfg.xml加上屬性.
<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">UTF-8</property>
mysql 的驅(qū)動(dòng)用3.0.15以上版本的,
加個(gè)Filter, 使用UTF-8字符集就可以了,
若使用Spring則寫(xiě)在spring中的sessionFactory里即可。
例如:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="connection.username">root</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/hibernate_table
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="myeclipse.connection.profile">
mySql hibernatetable
</property>
<property name="connection.password">12345678</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">UTF-8</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<mapping resource="cn/com/hibernate/Demo/Guestbook.hbm.xml" />
<mapping resource="cn/com/hibernate/Demo/GMapping.hbm.xml" />
<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">UTF-8</property>
mysql 的驅(qū)動(dòng)用3.0.15以上版本的,
加個(gè)Filter, 使用UTF-8字符集就可以了,
若使用Spring則寫(xiě)在spring中的sessionFactory里即可。
例如:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="connection.username">root</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/hibernate_table
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="myeclipse.connection.profile">
mySql hibernatetable
</property>
<property name="connection.password">12345678</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">UTF-8</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<mapping resource="cn/com/hibernate/Demo/Guestbook.hbm.xml" />
<mapping resource="cn/com/hibernate/Demo/GMapping.hbm.xml" />
您可能感興趣的文章:
- 詳解mysql數(shù)據(jù)庫(kù)中文亂碼問(wèn)題
- 在CMD中操作mysql數(shù)據(jù)庫(kù)出現(xiàn)中文亂碼解決方案
- 解決Windows10下mysql5.5數(shù)據(jù)庫(kù)命令行中文亂碼問(wèn)題
- Mac Mysql數(shù)據(jù)庫(kù)中文亂碼問(wèn)題解決
- MYSQL數(shù)據(jù)庫(kù)使用UTF-8中文編碼亂碼的解決辦法
- php頁(yè)面,mysql數(shù)據(jù)庫(kù)轉(zhuǎn)utf-8亂碼,utf-8編碼問(wèn)題總結(jié)
- MySql修改數(shù)據(jù)庫(kù)編碼為UTF8避免造成亂碼問(wèn)題
- java連接mysql數(shù)據(jù)庫(kù)亂碼的解決方法
- MYSQL數(shù)據(jù)庫(kù)導(dǎo)入數(shù)據(jù)時(shí)出現(xiàn)亂碼的解決辦法
- Mysql數(shù)據(jù)庫(kù)亂碼問(wèn)題的對(duì)應(yīng)方式
相關(guān)文章
MySQL數(shù)據(jù)庫(kù)分區(qū)功能的使用教程
這篇文章主要介紹了MySQL數(shù)據(jù)庫(kù)分區(qū)功能的使用教程,文中特別講解了MySQL分表和分區(qū)的區(qū)別以及聯(lián)系,需要的朋友可以參考下2016-05-05
自學(xué)MySql內(nèi)置函數(shù)知識(shí)點(diǎn)總結(jié)
在本篇文章里小編給大家整理的是關(guān)于MySql內(nèi)置函數(shù)的知識(shí)點(diǎn)總結(jié)內(nèi)容,需要的朋友們可以學(xué)習(xí)參考下。2020-01-01
MySQL中隨機(jī)生成固定長(zhǎng)度字符串的方法
在MySQL中有時(shí)需要隨機(jī)生成數(shù)字或字符串,隨機(jī)生產(chǎn)數(shù)字可直接使用rand()函數(shù),但是要隨機(jī)生成字符串就比較麻煩。2010-12-12
Linux centos7環(huán)境下MySQL安裝教程
這篇文章主要為大家詳細(xì)介紹了Linux centos7環(huán)境下MySQL安裝教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-03-03
MySQL如何創(chuàng)建可以遠(yuǎn)程訪問(wèn)的root賬戶詳解
作為MySQL數(shù)據(jù)庫(kù)管理員,創(chuàng)建遠(yuǎn)程用戶并設(shè)置相應(yīng)的權(quán)限是一項(xiàng)常見(jiàn)的任務(wù),下面這篇文章主要給大家介紹了關(guān)于MySQL如何創(chuàng)建可以遠(yuǎn)程訪問(wèn)的root賬戶的相關(guān)資料,需要的朋友可以參考下2024-04-04

