Hibernate 连接MYSQL数据库插入的中文数据都变成了问号!插入英文没问题,可是通过MYSQL数据内直接插入中文数据却能正常显示,只是java程序(通过hibernate)连接数据库插入的中文数据变成问号。请问如何解决啊?

解决方案 »

  1.   

    请问高人,如何改,我的url:
    <property name="hibernate.connection.url">jdbc:mysql://localhost/hibernate_many2one</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">bjsxt</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.show_sql">true</property>
      

  2.   

    方法很多,
    第一,根据你的工程的编码去同步数据库的编码。将你的mysql server编码改一下(在根目下的一个my.ini文件中),再将你的DB改一下编码。
    第二,在hibernate.cfg.xml把url改为jdbc:mysql://localhost:3306/jpa?useUnicode=true&amp;characterEncoding=UTF-8
    这里我用的是u8!
      

  3.   


    数据库没问题啊。主要是Hibernate配置有问题,用你的第二种方法任然不行啊
      

  4.   

    修改mysql安装路径下的my.ini中把default-character-set=gbk 就可以啦 
      

  5.   

    你如果用的是eclipse 那看一下windows->Preferences->General->workspace 里面的编码是不是GBK(或默认)的