java - 我正在使用休眠将我的 Java 程序连接到 mysql 数据库,但出现错误
问题描述
堆栈跟踪:
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>
解决方案
请检查您的 MySQL 服务器是否正在运行:
对于 Unix (sh):
sudo netstat -npl | grep 3306
对于 Windows (cmd):
netstat -aon | find /i "3306"
如果为空,则运行 MySQL-server或更改端口
推荐阅读
- .net - WCF Webservice 请求:在 SecurityTokenReference 中添加引用标记而不是 KeyIdentifier 标记
- audiokit - Audiokit Control 交互捕获
- jdbc - 即使在指定 quote.sql.identifiers=NEVER 之后,table.whitelist 也区分大小写
- python - 当我有高度不平衡的数据时,我应该平衡测试集吗?
- javascript - How to Create Chart.JS Bar Graph with Min, Max & Average
- android - 第三方应用程序是否可以从 ram 中删除未使用的进程?
- flutter - 如何在模拟器中测试颤振指纹代码?
- php - 如何将字段从文本更改为选项框?
- javascript - 如何在动态附加的内部元素上附加点击事件?
- docker - 泊坞窗图像未运行