hibernate的配置出现的错误问题汇总

<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
    	<!-- 一、 数据库连接的参数配置 -->
    	<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/app?useUnicode=true&amp;characterEncoding=utf8</property>
    	<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    	<property name="hibernate.connection.username">root</property>
    	<property name="hibernate.connection.password">root</property>
    	<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    
    	<!-- 二、 hibernate其他常用配置 -->
    	<property name="hibernate.show_sql">true</property><!--
    	<property name="hibernate.format_sql">true</property>
    	--><property name="hibernate.hbm2ddl.auto">update</property>
    	
    	<!-- 三、加载映射文件
    	<mapping resource="cn/itcast/a_status/Employee.hbm.xml"/>-->
    	<mapping resource="entity/User.hbm.xml"/> 
    	
    </session-factory>
</hibernate-configuration>

1,url要加上utf-8,不加会出现

Unknown initial character set index '255' received from server. Initial client character 

解决:https://blog.csdn.net/txwtech/article/details/80787886

2,&不能直接写,应改为:&amp;不然会报错(在xml配置文件中配置数据库utl时,要使用&的转义字符也就是&amp;)

数据库连接报错:对实体 "characterEncoding" 的引用必须以 ';' 分隔符结尾

3.还要加上时区

jdbc:mysql://localhost:3306/houses?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC

4.新版本的驱动是

com.mysql.cj.jdbc.Driver

serverTimezone=Asia/Shanghai(解决时差问题)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值