2013-03-24 177 views
2

我尝试使用mysql,所以包括mysql.jdbc,这些都是我的休眠设置。休眠 - 无法连接到数据库

<?xml version="1.0" encoding="UTF-8"?> 
    <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 
    <hibernate-configuration> 
     <session-factory> 
     <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> 
     <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> 
     <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/TekirMobile</property> 
     <property name="hibernate.connection.username">root</property> 
     <property name="hibernate.connection.password">fenderpass</property> 
     <property name="hibernate.show_sql">true</property> 
     <property name="hibernate.current_session_context_class">thread</property> 
     <property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property> 
     </session-factory> 
    </hibernate-configuration> 

但是当我尝试connecto分贝我得到这个错误:

Unable to connect: Cannot establish a connection jdbc:mysql://localhost:3306/mydbname using apache.org.derby.jdbc.ClientDriver(Unable to find a suitable driver) 

为什么我得到这个错误我甚而不德比使用?

+0

首先,你需要关闭防火墙,然后做其他。 – 2013-03-24 15:14:47

+0

因此,如果我不关闭防火墙,更改不生效? – user2153566 2013-03-24 15:19:04

+0

@ user2153566,请点击此链接。 http://www.tutorialspoint.com/hibernate/hibernate_configuration.htm – Umair 2015-03-27 06:14:50

回答

0

您没有在任何地方指定连接驱动程序。它告诉你它试图使用apache.org.derby.jdbc.ClientDriver进行连接。

指定MySQL驱动程序,以下列方式:

<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>