spring boot 无法连接数据库

我尝试使用数据库连接构建 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 文件


我不明白这有什么问题。


白猪掌柜的
浏览 144回答 2
2回答

肥皂起泡泡

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

蓝山帝景

其重复票证,请检查:https:/stackoverflow.com/questions/2983248/com-mysql-jdbc-exceptions-jdbc4-communicationsexception-communications-link-fai

潇湘沐

  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.MySQL5Dialecthibernate.dialect=org.hibernate.dialectMySQL5Dialecthibernate.show_sql=truehibernate.hbm2ddl.auto=createhibernate.ddl-auto=validatehibernate.connection.url=jdbc:mysql://localhost:3306/axa_india?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNullhibernate.connection.username=roothibernate.connection.password=root
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java