Java org.hibernate.exception.jdbconnectionexception:无法打开连接

Java org.hibernate.exception.jdbconnectionexception:无法打开连接,java,hibernate,Java,Hibernate,出于测试目的,我编写了非常小的代码,反复抛出与jdbc驱动程序相关的异常 package sally; import org.hibernate.Session; import org.hibernate.Transaction; public class MainClass { public static void main(String args[]){ try{ Session session=HibernateUtil.get

出于测试目的,我编写了非常小的代码,反复抛出与jdbc驱动程序相关的异常

   package sally;

   import org.hibernate.Session;
   import org.hibernate.Transaction;

   public class MainClass {

   public static void main(String args[]){

    try{
        Session session=HibernateUtil.getSession();
        Transaction tx=session.beginTransaction();
        Employee ee=new Employee("abx","asd",2000);
        session.save(ee);
        tx.commit();


    }catch(Exception e){
        e.printStackTrace();
    }
  }
}
这是我的ben/pojo映射类

package sally;

   public class Employee {
   private int id;
   private String firstName; 
   private String lastName;   
   private int salary;  

  public Employee() {}
  public Employee(String fname, String lname, int salary) {
  this.firstName = fname;
  this.lastName = lname;
  this.salary = salary;
  }
   public int getId() {
   return id;
 }
  public void setId( int id ) {
   this.id = id;
 }
  public String getFirstName() {
  return firstName;
  }
      public void setFirstName( String first_name ) {
      this.firstName = first_name;
      }
      public String getLastName() {
      return lastName;
       }
      public void setLastName( String last_name ) {
      this.lastName = last_name;
      }
        public int getSalary() {
        return salary;
      }
        public void setSalary( int salary ) {
        this.salary = salary;
      }
}


  <?xml version="1.0" encoding="utf-8"?>
  <!DOCTYPE hibernate-mapping PUBLIC 
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> 

 <hibernate-mapping>
   <class name="sally.Employee" table="EMPLOYEE">
     <meta attribute="class-description">
     This class contains the employee detail. 
     </meta>
     <id name="id" type="int" column="id">
      <generator class="native"/>
     </id>
    <property name="firstName" column="first_name" type="string"/>
    <property name="lastName" column="last_name" type="string"/>
    <property name="salary" column="salary" type="int"/>
  </class>
  </hibernate-mapping>
有人能看出这里出了什么问题吗


这是db列列表:first_name last_name salary。

您需要将mysql JDBC驱动程序JAR放在类路径上

您需要将mysql JDBC驱动程序JAR放在类路径上

org.hibernate.exception.jdbconnectionException:无法打开连接
未启动xampp和MySql。

org.hibernate.exception.JDBCConnectionException:无法打开连接当您尚未启动xampp和MySql时会发生这种情况。

必须更新驱动程序类的名称以及服务器时区(对我来说,这很疯狂,但必须这样做)

<?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.cj.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/hibernate?serverTimezone=UTC</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    </session-factory>
</hibernate-configuration>

com.mysql.cj.jdbc.Driver
jdbc:mysql://127.0.0.1:3306/hibernate?serverTimezone=UTC
根
org.hibernate.dialogue.mysqldialogue

必须更新驱动程序类的名称以及服务器时区(对我来说这很疯狂,但必须这样做

<?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.cj.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/hibernate?serverTimezone=UTC</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    </session-factory>
</hibernate-configuration>

com.mysql.cj.jdbc.Driver
jdbc:mysql://127.0.0.1:3306/hibernate?serverTimezone=UTC
根
org.hibernate.dialogue.mysqldialogue

这是您的主要问题:没有找到适合jdbc的驱动程序:mysql://localhost:3306/tesYou 可能还想在log4j配置中为hibernate设置一个日志追加器,以消除其余的干扰。是的!这是您的主要问题:没有找到适合jdbc的驱动程序:mysql://localhost:3306/test 是xammp中的主要问题。sql版本5.5.25a,mysql connector 5.1.5这是您的主要问题:没有找到适合jdbc的驱动程序:mysql://localhost:3306/tesYou 可能还想在log4j配置中为hibernate设置一个日志追加器,以消除其余的干扰。是的!这是您的主要问题:没有找到适合jdbc的驱动程序:mysql://localhost:3306/test 主要问题是.sql版本xammp中的5.5.25a,mysql连接器5.1.5谢谢李!我已经做了,iput mysql连接器jar 3.0.11和5.1.5都做了,但是错误仍然存在。检查xammp中的driverssql版本5.5.25a,mysql连接器5.1.5谢谢李!我已经做了,iput mysql连接器jar 3.0.11和5.1.5都做了,但是错误仍然存在。check xammp中的driverssql版本5.5.25a,mysql连接器5.1.5
<?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.cj.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/hibernate?serverTimezone=UTC</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    </session-factory>
</hibernate-configuration>