Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Eclipse-Hibernate:未找到适合jdbc的驱动程序:mysql://localhost:3306/hibernatedb_Java_Mysql_Eclipse_Hibernate_Jdbc - Fatal编程技术网

Java Eclipse-Hibernate:未找到适合jdbc的驱动程序:mysql://localhost:3306/hibernatedb

Java Eclipse-Hibernate:未找到适合jdbc的驱动程序:mysql://localhost:3306/hibernatedb,java,mysql,eclipse,hibernate,jdbc,Java,Mysql,Eclipse,Hibernate,Jdbc,我试图通过编写一个简单的java程序来学习Hibernate。我使用MySQL作为数据库,运行程序时出现上述错误。我在互联网上看到了许多解决方案,并尝试了一切可能的方法,但都没有成功。我做错了什么 配置文件: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http

我试图通过编写一个简单的java程序来学习Hibernate。我使用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.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernatedb</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">root</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>
        <property name="hbm2ddl.auto">create</property>
        <mapping resource="com/test/hibernate/student.hbm.xml" />
    </session-factory>
</hibernate-configuration>
类路径和库文件夹:


很可能您没有正确添加mysql连接器库,因为在您发布的运行配置的快照中,该库出现在一个名为“hibernate test”的项目中,该项目包含一个名为“mysql-connector-etc.jar”的文件,但这不是在类路径中设置jar的方法


这样做:最好在项目的Java构建路径中添加“mysql-connector-etc.jar”:弹出项目的上下文菜单,然后单击
Build Path>Configure Build Path>Libraries>add external jar
。然后选择mysql连接器JAR并输入。从那时起,Eclipse将把这个JAR包含到您应该执行的任何项目中(这样您就不必再关心它了)。

很可能您没有正确添加mysql连接器库,因为在您发布的运行配置的快照中,该库出现在名为“hibernate test”的项目中它包含一个名为“mysql-connector-etc.jar”的文件,但这不是在类路径中设置jar的方法


这样做:最好在项目的Java构建路径中添加“mysql-connector-etc.jar”:弹出项目的上下文菜单,然后单击
Build Path>Configure Build Path>Libraries>add external jar
。然后选择mysql连接器JAR并输入。从那时起,Eclipse将把这个JAR包含到您应该执行的任何项目中(这样您就不必再关心它了)。

在类路径上添加MySql连接器/J驱动程序来解决这个问题。@N00bPr0grammer,看起来它已经包含在OPtry使用jdk而不是jreAre提供的映像中。您是从Eclipse还是从命令行运行该程序的?@gundev刚刚尝试过,不起作用。请在类路径上添加MySql连接器/J驱动程序以解决此问题。@N00bPr0grammer,看起来它已经包含在OPtry使用jdk而不是jreAre提供的映像中。您是从Eclipse还是从命令行运行该程序的?@gundev刚刚尝试过,没有工作。
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.exception.JDBCConnectionException: Cannot open connection
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
    at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:420)
    at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
    at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)
    at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
    at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
    at com.test.hibernate.SimpleTest.main(SimpleTest.java:23)
Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/hibernatedb
    at java.sql.DriverManager.getConnection(DriverManager.java:689)
    at java.sql.DriverManager.getConnection(DriverManager.java:208)
    at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
    at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:417)
    ... 5 more