Intellij错误:找不到适合jdbc的驱动程序:mysql://127.0.0.1:3306 / person [英] Intellij ERROR: No suitable driver found for jdbc:mysql://127.0.0.1:3306/person

查看:4783
本文介绍了Intellij错误:找不到适合jdbc的驱动程序:mysql://127.0.0.1:3306 / person的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先我在这个论坛上找不到相关问题的答案。我是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'是我的数据库)我添加了必要的jar文件(或者至少我认为是这样),并且通常我遵循了我在此消息的第二行粘贴的网页中的所有步骤。请看看它,如果可以的话,帮助我。我所创建的所有文件和代码都可以从我粘贴的网站上看到。我几乎已经复制了这个例子。感谢您。

UPDATED

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>根< / 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>线程< / property>

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

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

解决方案

您必须使JDBC库可用于您的项目。只需将jar添加到项目目录中即可。



在您的项目中选择jar,右键单击并添加为一个库。




first of all I couldn't find an answer from related questions in this forum. I am new to Hibernate technology and I am trying to run a basic example from this page: http://www.roseindia.net/hibernate/hibernate4/firstHibernateApplication.shtml Although, in eclipse it worked fine, I've got a problem with Intellij IDEA. Specifically, I have an error in the hibernate.cfg.xml file which says:

" 'com.mysql.jdbc.Driver' is not assignable to 'java.sql.Driver' ".

And when I run the program a message appears saying: "ERROR: No suitable driver found for jdbc:mysql://127.0.0.1:3306/person Inserting Record Could not open connection"

('person' is my database) I have added the necessary jar files (or at least I think so) and generally I have followed all the steps from the webpage I pasted in the second line of this message. Please look at it and help me if you can. All the files and code I've created can be seen from the website I pasted. I've almost copied-pasted the example. Thank you.

UPDATED

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>

I' ve placed the connector jar file at the directory IdeaProjects\coreHibernateExample\lib. No, I am not running Tomcat, I guess I am running through Intellij. The import of the Mysql database has been made through Wampservers' phpmyadmin.

解决方案

You have to make the JDBC library jar available to your project. Just adding jar to your project directory does not accomplish that.

Select jar in your project, right click and add as a library.

这篇关于Intellij错误:找不到适合jdbc的驱动程序:mysql://127.0.0.1:3306 / person的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆