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

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

我正在使用 hibernate 將 Java 程序連接到 mysql 數據庫,但出現錯誤

我正在使用 hibernate 將 Java 程序連接到 mysql 數據庫,但出現錯誤

繁星coding 2023-09-20 19:13:44
堆棧跟蹤:Exception in thread "main" org.hibernate.exception.JDBCConnectionException: Could not open connection    at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:67)    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)    at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:304)    at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:169)    at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:67)    at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:160)    at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1396)    at com.telusko.DemoHibb.App.main(App.java:24)我的 Hibernate.cfg.xml 文件是:<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-configuration PUBLIC        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"><hibernate-configuration>    <session-factory>        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/neon</property>        <property name="hibernate.connection.username">root</property>        <property name="hibernate.connection.password">root</property>        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>        <property name="hbm2ddl.auto">update</property>    </session-factory></hibernate-configuration>
查看完整描述

2 回答

?
心有法竹

TA貢獻1866條經驗 獲得超5個贊

請檢查您的 MySQL 服務器是否正在運行:

對于 Unix (sh):

sudo netstat -npl | grep 3306

對于 Windows(cmd):

netstat -aon | find /i "3306"

如果為空則運行 MySQL-server更改端口


查看完整回答
反對 回復 2023-09-20
?
慕運維8079593

TA貢獻1876條經驗 獲得超5個贊

問題在于舊版本的 MySQL Connector/J 與 MySQL 8 的兼容性。我只需將 SQL Connector 版本升級為最新版本。

經過一番努力,我能夠找到問題所在。


查看完整回答
反對 回復 2023-09-20
  • 2 回答
  • 0 關注
  • 148 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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