【问题标题】:Intellij ERROR: No suitable driver found for jdbc:mysql://127.0.0.1:3306/personIntellij 错误:找不到适合 jdbc 的驱动程序:mysql://127.0.0.1:3306/person
【发布时间】:2020-10-17 11:09:15
【问题描述】:

首先,我在这个论坛中找不到相关问题的答案。我是 Hibernate 技术的新手,我正在尝试从此页面运行一个基本示例:http://www.roseindia.net/hibernate/hibernate4/firstHibernateApplication.shtml 虽然,在 Eclipse 中它运行良好,但我遇到了 Intellij IDEA 的问题。具体来说,我在 hibernate.cfg.xml 文件中有一个错误:

“‘com.mysql.jdbc.Driver’不可分配给‘java.sql.Driver’”。

当我运行程序时,会出现一条消息: "错误:找不到适合 jdbc 的驱动程序:mysql://127.0.0.1:3306/person 插入记录无法打开连接"

('person' 是我的数据库)我已经添加了必要的 jar 文件(或者至少我认为是这样),并且通常我已经按照我粘贴在此消息第二行的网页中的所有步骤进行操作。如果可以的话,请看一下并帮助我。我创建的所有文件和代码都可以从我粘贴的网站上看到。我几乎复制粘贴了这个例子。谢谢。

更新

hibernate.cfg.xml:

<?xml version='1.0' encoding='utf-8'?>
 <!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//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://127.0.0.1:3306/person
    </property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password"/>
    <property name="hibernate.connection.pool_size">10</property>
    <property name="show_sql">true</property>
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.current_session_context_class">thread</property>

</session-factory>
</hibernate-configuration>

我已将连接器 jar 文件放在目录 IdeaProjects\coreHibernateExample\lib 中。不,我没有运行 Tomcat,我想我正在通过 Intellij 运行。 Mysql 数据库的导入是通过 Wampservers 的 phpmyadmin 完成的。

【问题讨论】:

  • 你能发布你的配置文件吗?另外,您能否告诉我(我们)您是自行运行 Tomcat(或任何应用服务器)还是通过 IntelliJ 运行?另外,你把 MySQL Connector/j Jar 文件放在哪里了?

标签: database hibernate intellij-idea hibernate-mapping


【解决方案1】:

您必须使 JDBC 库 jar 可用于您的项目。只是将 jar 添加到您的项目目录中并不能做到这一点。

在你的项目中选择jar,右键添加为库。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-21
    • 2014-06-18
    • 1970-01-01
    • 2012-05-23
    • 2021-03-23
    • 1970-01-01
    • 2014-04-18
    相关资源
    最近更新 更多