为了账号安全,请及时绑定邮箱和手机立即绑定

spring boot 无法连接数据库

spring boot 无法连接数据库

白猪掌柜的 2024-01-17 16:44:22
我尝试使用数据库连接构建 RestFull Web 服务。但这似乎没有与数据库连接。我在控制台中收到此错误。   com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.        at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.18.jar:8.0.18]        at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.18.jar:8.0.18]        at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836) ~[mysql-connector-java-8.0.18.jar:8.0.18]The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_162]    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[na:1.8.0_162]    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[na:1.8.0_162]Caused by: java.net.UnknownHostException: db_example    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) ~[na:1.8.0_162]    at java.net.InetAddress$2.lookupAllHostAddr(Unknown Source) ~[na:1.8.0_162]Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:275) ~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237) ~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]这是我的 application.property 文件我不明白这有什么问题。
查看完整描述

2 回答

?
肥皂起泡泡

TA贡献1829条经验 获得超6个赞

我认为这里的主机名有问题。因此,请检查一次主机名,例如 localhost(或)您正确的数据库托管地名。

因为它显示像unknownHostException这样的异常。


查看完整回答
反对 回复 2024-01-17
?
蓝山帝景

TA贡献1843条经验 获得超7个赞

查看完整回答
反对 回复 2024-01-17
?
潇湘沐

TA贡献1816条经验 获得超6个赞

  spring.datasource.url=jdbc:mysql://localhost:3306/db_example

    spring.datasource.username = root

    spring.datasource.password = root

    spring.jpa.properties.hibernate.dialect =org.hibernate.dialect.MySQL5Dialect


hibernate.dialect=org.hibernate.dialectMySQL5Dialect

hibernate.show_sql=true

hibernate.hbm2ddl.auto=create

hibernate.ddl-auto=validate


hibernate.connection.url=jdbc:mysql://localhost:3306/axa_india?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull

hibernate.connection.username=root

hibernate.connection.password=root


查看完整回答
反对 回复 2024-01-17
  • 2 回答
  • 0 关注
  • 44 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信