Aze_Zer0 2015-01-17 10:07 采纳率: 0%
浏览 1576
已结题

hiberenate Mysql 中文问题,网上地还是不行诶

不管是在配置文件里面改连接地配置还是数据库的字符集都不行
如果是改配置,会直接报错,
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/'

  • 写回答

1条回答 默认 最新

  • Aze_Zer0 2015-01-18 04:33
    关注

    已经解决了,, true
    UTF-8

    
    

    将mysql地字符集也统一为utf-8
    注意,要重启一下

    评论

报告相同问题?

悬赏问题

  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划