简体   繁体   English

如何解决==> org.hibernate.exception.GenericJDBCException:无法打开连接

[英]how to resolve ==> org.hibernate.exception.GenericJDBCException: Could not open connection

when i execute my Main class i get this execution cant figure out the issue point 当我执行我的主类时,我得到这个执行无法弄清问题点

the error comes in the line Transaction tr = session.beginTransaction(); 错误出现在事务TR = session.beginTransaction();行中

error stack says : 错误堆栈说:

ERROR: Access denied for user 'root'@'localhost' (using password: NO)
error===>org.hibernate.exception.GenericJDBCException: Could not open connection

my Main class File : 我的主类文件:

package com.hussi.model;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class Main {
    public static void main(String[] args) 
    {
        User user = new User();
        user.setUser_id(1);
        user.setUsername("hussi");
        user.setPassword("maria");
        SessionFactory sesionFactory = new Configuration().configure().buildSessionFactory() ;
        Session session = sesionFactory.openSession();
        try{
        Transaction tr = session.beginTransaction();
        session.save(user);
        }
        catch(Exception e)
        {
            System.out.println("error===>"+e);
        }

        finally
        {
        session.flush();
        session.close();
        }
    }

}

my model file 我的模型文件

package com.hussi.model;

public class User 
{
    int user_id;
    String username;
    String password;

    public int getUser_id() {
        return user_id;
    }
    public void setUser_id(int user_id) {
        this.user_id = user_id;
    }


    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }


    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }

    public String toString()
    {
        return "username==>"+this.username+" : password==>"+this.password;
    }

}

my user.hbm.xml file 我的user.hbm.xml文件

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="com.hussi.model.User" table="users">
         <id name="user_id" type="int" column="user_id">
            <generator class="increment" />
        </id>

        <property name="username">
            <column name="username"/>
        </property>

        <property name="password">
            <column name="password"/>
        </property>
    </class>
</hibernate-mapping>

my hibernate configuration file : hibernate.cfg.xml 我的休眠配置文件: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>
        <!-- Database connection settings -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/my_hibernate_1</property>
        <property name="connection.username">root</property>
        <property name="connecttion.password">root</property>

        <!-- Database connection settings -->
        <property name="connection.pool_size">1</property>

        <!-- MySql Dialect -->
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">false</property>

        <mapping resource="user.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

I believe you need to reset your database password. 我相信您需要重设数据库密码。 Follow this link to do the same: 单击此链接以执行相同操作:

http://dev.mysql.com/doc/refman/5.1/en/resetting-permissions.html http://dev.mysql.com/doc/refman/5.1/en/resetting-permissions.html

or the user priviliges are not correct. 或用户权限不正确。 Follow this to set priviliges: 请按照以下步骤设置特权:

http://dev.mysql.com/doc/refman/5.1/en/default-privileges.html http://dev.mysql.com/doc/refman/5.1/en/default-privileges.html

暂无
暂无

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

相关问题 Hibernate - org.hibernate.exception.GenericJDBCException:无法打开连接 - Hibernate - org.hibernate.exception.GenericJDBCException: Cannot open connection 网络适​​配器无法建立连接org.hibernate.exception.GenericJDBCException:无法打开连接 - The Network Adapter could not establish the connection org.hibernate.exception.GenericJDBCException: Could not open connection org.hibernate.exception.GenericJDBCException:无法打开连接 - org.hibernate.exception.GenericJDBCException: Cannot open connection org.hibernate.exception.GenericJDBCException:无法打开连接 - org.hibernate.exception.GenericJDBCException: Cannot open connection 发生org.hibernate.exception.GenericJDBCException:无法为长时间运行的进程打开连接 - Occurrence of org.hibernate.exception.GenericJDBCException: Could not open connection for long running process org.hibernate.exception.GenericJDBCException:无法插入: - org.hibernate.exception.GenericJDBCException: could not insert: Spring Roo JPA MS SQL Server无法打开JPA EntityManager org.hibernate.exception.GenericJDBCException:无法打开连接 - Spring Roo JPA MS SQL Server Could not open JPA EntityManager org.hibernate.exception.GenericJDBCException: Could not open connection org.hibernate.exception.GenericJDBCException - org.hibernate.exception.GenericJDBCException Hibernate + PostgreSQL引发异常:org.hibernate.exception.GenericJDBCException:无法打开连接 - Hibernate + PostgreSQL throws an Exception: org.hibernate.exception.GenericJDBCException: Cannot open connection org.hibernate.exception.GenericJDBCException:无法在hibernate中执行语句 - org.hibernate.exception.GenericJDBCException: could not execute statement in hibernate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM