亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 254 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號