不管是在配置文件里面改连接地配置还是数据库的字符集都不行
如果是改配置,会直接报错,
CREATE TABLE t2
(id
int(11) NOT NULL AUTO_INCREMENT,title
varchar(800) DEFAULT NULL,content
varchar(200) DEFAULT NULL,
PRIMARY KEY (id
)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<class name="po.T2Entity" table="t2" schema="" catalog="j2ee">
<id name="id">
<column name="id" sql-type="int" not-null="true"/>
</id>
<property name="title">
<column name="title" sql-type="varchar" length="800"/>
</property>
<property name="content">
<column name="content" sql-type="varchar" length="200"/>
</property>
</class>
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
jdbc:mysql://127.0.0.1:3306/j2ee
com.mysql.jdbc.Driver
root
<property name="connection.password"></property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<!-- DB schema will be updated if needed -->
<!-- <property name="hbm2ddl.auto">update</property> -->
<mapping resource="po/T2Entity.hbm.xml"/>
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.classic.Session;
import po.T2Entity;
/**
- Created by bruce on 15/1/17. */ public class Main { public static void main(String args[]) { Configuration configuration = new Configuration().configure(); SessionFactory sf = configuration.buildSessionFactory(); Session session = sf.openSession(); Transaction tx = session.beginTransaction(); T2Entity t = new T2Entity(); t.setTitle("我的hibernate"); t.setContent("我今天在学习Hibernate"); session.save(t); tx.commit(); session.close(); } } 'character_set_client','utf8' 'character_set_connection','utf8' 'character_set_database','utf8' 'character_set_filesystem','binary' 'character_set_results','utf8' 'character_set_server','utf8' 'character_set_system','utf8' 'character_sets_dir','/usr/local/mysql-advanced-5.6.22-osx10.8-x86_64/share/charsets/'