hibernate配置mysql8.0以上版本

大三开的J2EE的课,第一节就遇到个大坑,我用的是之前安装的mysql8.0,死活运行不了

一度怀疑是代码或是eclipse出了问题

在工作室电脑上试了一下,代码没问题,原来是自己电脑数据库版本高的事

贴出原来的hibernate.cfg.xml配置(这个配置是正确的,用于mysql5没问题)

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

<hibernate-configuration>
	<session-factory>
		<property name="hibernate.connection.url">jdbc:mysql://localhost/hibernate_first</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>
		<property name="hibernate.show_sql">true</property>
		
		<mapping resource="*/User.hbm.xml"/><--!  *是路径-->
	</session-factory>
</hibernate-configuration>

报错提示

搞了一下午可算成功了

贴出修改后的hibernate.cfg.xml

<session-factory>
	    <!--数据库名称:hibernate_first -->		
		<property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
	    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernate_first?useSSL=false&amp;serverTimezone=UTC</property>
		<property name="hibernate.connection.username">root</property>
		<property name="hibernate.connection.password">root</property>
	
		<!-- 设置方言 -->
		<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
		

		<mapping resource="test/User.hbm.xml"/>
	</session-factory>

其中驱动,url和方言都需要修改

 

 

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值