简体   繁体   English

Eclipse - Hibernate:没有为jdbc找到合适的驱动程序:mysql:// localhost:3306 / hibernatedb

[英]Eclipse - Hibernate : No suitable driver found for jdbc:mysql://localhost:3306/hibernatedb

I am trying to learn Hibernate by writing a simple java program. 我试图通过编写一个简单的java程序来学习Hibernate。 I'm using MySQL as the database, and I get the above error when running the program. 我使用MySQL作为数据库,运行程序时出现上述错误。 I saw a number of solutions for this on the internet and tried everything possible, to no avail. 我在互联网上看到了很多解决方案,并尝试了一切,但无济于事。 What am I doing wrong? 我究竟做错了什么?

Configuration file: 配置文件:

<?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>

Console output: 控制台输出:

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

Classpath & lib folder: Classpath&lib文件夹: Classpath&lib文件夹

lib文件夹

Most probably you didn't add the mysql-connector library correctly, because in the snapshot from the Run configuration you posted, that library appears within a project called "hibernate test" which contains a file named "mysql-connector-etc.jar", but that is not the way to set a JAR within a classpath. 很可能你没有正确添加mysql-connector库,因为在你发布的Run配置的快照中,该库出现在一个名为“hibernate test”的项目中,该项目包含一个名为“mysql-connector-etc.jar”的文件,但这不是在类路径中设置JAR的方法。

Do it this way: It's better that you add the "mysql-connector-etc.jar" right within your project's Java Build Path: Pop up the project's contextual menu, and the Build Path > Configure Build Path > Libraries > Add external jars . 这样做:最好在项目的Java Build Path中添加“mysql-connector-etc.jar”:弹出项目的上下文菜单,以及Build Path > Configure Build Path > Libraries > Add external jars Then select the mysql-connector JAR and enter. 然后选择mysql-connector JAR并输入。 From then on, Eclipse will include this JAR into any execution of your project you should do (so you won't have to care about it anymore). 从那时起,Eclipse将把这个JAR包含在你应该执行的项目的任何执行中(所以你不必再关心它了)。

暂无
暂无

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

相关问题 休眠 - 无法建立 JDBC 连接 [jdbc:mysql//localhost:3306/hibernatedb - Hibernate - Unable to make JDBC Connection [jdbc:mysql//localhost:3306/hibernatedb JDBC JAVA找不到适合的驱动程序jdbc:mysql:// localhost:3306 / voting - JDBC JAVA No suitable driver found for jdbc:mysql://localhost:3306/voting 发现此错误“没有找到适合 jdbc:mysql//localhost:3306/student 的驱动程序” - Found this error "No suitable driver found for jdbc:mysql//localhost:3306/student" 如何解决:找不到适合jdbc的驱动:mysql://localhost:3306/sampledb - How to solve: No suitable driver found for jdbc:mysql://localhost:3306/sampledb 错误:找不到适用于jdbc:mysql:// localhost:3306 / test的驱动程序 - ERROR: No suitable driver found for jdbc:mysql://localhost:3306/test 找不到适用于jdbc:mysql:// localhost:3306 / jpa的驱动程序 - No suitable driver found for jdbc:mysql://localhost:3306/ jpa 找不到适用于jdbc:mysql // localhost:3306 / test的驱动程序 - No suitable driver found for jdbc:mysql//localhost:3306/test 找不到适用于jdbc:mysql:// localhost:3306 / test的驱动程序 - No suitable driver found for jdbc:mysql://localhost:3306/test 找不到适用于jdbc:mysql / localhost:3306 / world的驱动程序 - No suitable driver found for jdbc:mysql/localhost:3306/world 找不到适用于jdbc:mysql // localhost:3306 / demo的驱动程序吗?useSSL = false - No suitable driver found for jdbc:mysql//localhost:3306/demo?useSSL=false
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM