简体   繁体   English

数据库无法连接 spring 启动

[英]Database can't connect with spring boot

I tried to build RestFull webservice with db connection.我尝试使用数据库连接构建 RestFull webservice。 But this seems to not connecting with the database.但这似乎没有与数据库连接。 And I get this error in my console.我在控制台中收到此错误。

   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]

Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:100) ~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54) ~[hibernate-core-5.4.6.Final.jar:5.4.6.Final]

This is my application.property file这是我的 application.property 文件

server.port=8092

#spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:mysql://db_example:3306/db_example
spring.datasource.username=root
spring.datasource.password=


#spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=create

I can't figure out what is the wrong with this.我无法弄清楚这有什么问题。

    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

I think the host name is something wrong here.So Kindly check once the host machine name like localhost (or) your proper DB hosted place name.我认为这里的主机名有问题。所以请检查主机名,如 localhost(或)您正确的数据库托管地名。

Because it is showing Exception like unknownHostException.因为它显示了类似unknownHostException 的异常。

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

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