【JPA】关于eclipse中JPA项目运行报错ERROR: The server time zone value ‘Öйú±ê׼ʱ¼ä‘ is u。。。的解决办法

在最近的实验中,我遇到了这样一个报错,鉴于没能在csdn上搜索到解决办法,将自己的解决方法放在这里。

错误状态形如下图:

解决的方法是在persistence.xml配置文件中的url的value中加入数据库名后的一段代码。

配置文件内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
    xmlns="http://xmlns.jcp.org/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
    http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="firstJPA2.1" transaction-type="RESOURCE_LOCAL">
        <class>entity.User</class>
        <properties>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3406/testDB?useUnicode=true&amp;characterEncoding=utf-8&amp;useSSL=false&amp;serverTimezone = GMT"/>
            <property name="javax.persistence.jdbc.user" value="root"/>
            <property name="javax.persistence.jdbc.password" value="123"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
        </properties>
    </persistence-unit>
</persistence>

所需要添加的代码是:

?useUnicode=true&amp;characterEncoding=utf-8&amp;useSSL=false&amp;serverTimezone = GMT

注意!!!这段代码一定要加在原来的jdbc.url的value中数据库名称的后面,还有错误可能是因为数据库未启动或者数据库的连接密码不正确,记得检查好persistence.xml配置文件中的信息。还有可能就是相应的jar包没有导入,注意前往项目的Build Path中配置。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值