Spring MVC- Hibernate:org.hibernate.exception.GenericJDBCException:无法打开连接

时间:2016-03-18 06:15:28

标签: mysql hibernate spring-mvc

我正在开发一个maven示例项目,我在其中使用MySQL,Spring和Hibernate。 我在我的mac中使用终端创建了一个数据库。使用以下命令登录mysql并创建数据库和表。

    $ sudo -s
    Password:
    bash-3.2# mysql -u root -p
    Enter password:

在我的jdbc.properties文件中,我有:

    jdbc.driverClassName = com.mysql.jdbc.Driver
    jdbc.url = jdbc:mysql://localhost:3306/sample
    jdbc.username = root    
    jdbc.password = root
    hibernate.dialect = org.hibernate.dialect.MySQLDialect
    hibernate.show_sql = true
    hibernate.format_sql = true

在启动网址时,我会看到这个,

HTTP Status 500 - Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Could not open connection


exception:
    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Could not open connection

root cause:
    org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Could not open connection

root cause:
    org.hibernate.exception.GenericJDBCException: Could not open connection

root cause:
    java.sql.SQLException: Access denied for user 'root '@'localhost' (using password: YES)

我不熟悉使用终端和命令。任何人都可以告诉我这里的问题是什么,jdbc.username和jdbc.password应该是什么。我没有查询浏览器,我只能使用终端。

1 个答案:

答案 0 :(得分:0)

我想“root @ localhost”

缺少特权

以下是授予权限的步骤

$ sudo -s
  Password:
  bash-3.2# mysql -u root -p
  Enter password:

登录后,授予root @ localhost

权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'thepassword' WITH GRANT OPTION;