繁体   English   中英

使用Hibernate创建MySQL数据库

[英]MySQL database creation with Hibernate

我正在尝试以编程方式配置休眠并在MySQL中生成数据库架构和表。 这是休眠配置

 configuration.setProperty(AvailableSettings.DIALECT, "org.hibernate.dialect.MySQL5Dialect")
            .setProperty(AvailableSettings.URL, "jdbc:mysql://localhost/ritm?autoReconnect=true&characterEncoding=UTF-8&useUnicode=true&createDatabaseIfNotExist=true")
            .setProperty(AvailableSettings.USER, "root")
            .setProperty(AvailableSettings.PASS, "gjnjkjr")
            .setProperty(AvailableSettings.DRIVER, "com.mysql.jdbc.Driver")
            .setProperty(AvailableSettings.POOL_SIZE,"1");

当我用Maven运行它时,我得到以下警告

WARN: HHH000342: Could not obtain connection to query metadata : Could not create connection to database server. Attempted reconnect 3 times. Giving up.

然后是例外

апр 04, 2013 10:31:53 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: 08001
апр 04, 2013 10:31:53 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
org.hibernate.exception.JDBCConnectionException: Could not open connection
    at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:67)

有人可以描述吗?

您是否尝试过将端口号附加到URL。 我知道这似乎很愚蠢,但是,数据库通信依赖端口号,而且我注意到您没有在URL中包含端口号。 例如,如果您使用的是MySQL,则端口号为3306。因此JDBC URL如下所示:

AvailableSettings.URL, "jdbc:mysql://localhost:3306/ritm?autoReconnect=true&characterEncoding=UTF-8&useUnicode=true&createDatabaseIfNotExist=true"

暂无
暂无

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

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