我学习hibernate,向数据库中插入数据的时候出现了乱码,我的配置都是正确的,就是如果插入中文就出现乱码。请各位指点!

解决方案 »

  1.   

    mysql的中文问题是老问题了吧,随便上网一搜就是一堆。
    你都做哪些配置了?贴出来看看
      

  2.   

    <hibernate-configuration>
    <session-factory>
    <property name="hibernate.connection.url">jdbc:mysql://localhost/hibernate</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">123456</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.show_sql">true</property>
    <mapping resource="com/ysj/hibernate/User.hbm.xml" />
    </session-factory>
    </hibernate-configuration>
      

  3.   

    是不是字符集问题?上网查下mysql这方面的设置吧,用mysql自己的客户端或是第三方客户端看下中文操作有不有问题先吧。
      

  4.   


    <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/hibernate?useUnicode=true&amp;characterEncoding=GB2312 </property>
    这样表示你建的数据库采用中文编码
      

  5.   

    1、安装mysql时将语言设为gb2312
    2、程序连库时<property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/hibernate?useUnicode=true&amp;characterEncoding=GB2312 </property> 
      

  6.   

    一般是你的mysql没有配好编码,注意mysql每一个表,每一个字段都要是gb2312的才行
      

  7.   

    1、安装mysql时将语言设为gb2312 
    2、程序连库时 <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/hibernate?useUnicode=true&amp;characterEncoding=GB2312 </property> 经过这几个步骤基本就可以了。
      

  8.   

    每一个表的下面都有该表的属性
    中间有个选项选gb2312,utf8均可
    还有安装MySQL之前由此选项
    不是配置文件问题