繁体   English   中英

Hibernate-MySQL连接

[英]Hibernate-MySQL connection

我是Java网络的新手。 我正在使用Hibernate和MySQL使用Java Web开发应用程序。 问题是当我尝试登录时,如果我尝试连接远程数据库,有时会引发通信链接失败异常。 是什么导致此问题? (我还更改了超时值,再次引发了异常。)

休眠版本:4.3.3。最终

Glassfish服务器:4.1

相关错误ss: http : //hackengine-er.com/exceptions/link-failure.png

项目源代码: https : //github.com/Muslum10cel/Vaccine

我的hibernate.cfg.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <hibernate-configuration>
      <session-factory>
        <property name="hibernate.dialect">{MySQLDialect}</property>
        <property name="hibernate.connection.driver_class">{jdbcdriver}</property>
        <property name="hibernate.connection.url">{connectionstring}</property>
        <property name="hibernate.connection.username">{username}</property>
        <property name="hibernate.connection.password">{password}</property>
        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.hbm2ddl.auto">update</property>
        <property name="hibernate.current_session_context_class">thread</property>
        <property name="hibernate.c3p0.timeout">0</property>
     </session-factory>

      <!-- Entity mappings -->
   </hibernate-configuration>

谢谢你的帮助

第一步,我建议更改一些配置:

  1. 使用org.hibernate.dialect.MySQL5Dialect代替org.hibernate.dialect.MySQLDialect
  2. 使用此驱动程序com.mysql.cj.jdbc.Driver代替com.mysql.jdbc.Driver
  3. 删除?autoReconnect=true
  4. 您正在使用root用户访问数据库, 我建议创建一个专用用户
  5. 您没有提及任何密码。 即使您使用的是root用户,它也具有密码。 用它。

org.hibernate.dialect.MySQL5Dialect

<property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property> 

<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/vaccine</property>

<property name="hibernate.connection.username">root</property>

<property name="hibernate.connection.password">root_password_missing</property>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM