hibernate使用中错误记录

hibernate.cfg.xml和Student.hbm.xml如果在同一个包下,那么hibernate.cfg.xml配置中就不需要Student.hbm.xml的完整报名

hibernate使用中错误记录_第1张图片
360反馈意见截图16290621396846.png

插入到数据库的数据出现问号/乱码,是因为项目是GBK格式,但是建数据库的时候指定为utf-8格式,这样就出问题了。
hibernate使用中错误记录_第2张图片
360反馈意见截图166009039410283.png

hibernate.cfg.xml
①在xml的配置文件中 “&”要用 “& ” 代替
②my.ini default-character-set=utf8 设置的新建数据库默认的字符编码,你再看看你自己的数据库的字符编码是什么。再不行用navicat插入条utf8编码的数据试试就知道了




    
        com.mysql.jdbc.Driver
        
         jdbc:mysql://localhost:3306/hibernate?useUnicode=true&characterEncoding=utf8 
        root
        

        true 
        true
        create

        org.hibernate.dialect.MySQLDialect 

        
    


你可能感兴趣的:(hibernate使用中错误记录)