且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Intellij错误:找不到适合jdbc的驱动程序:mysql://127.0.0.1:3306 / person

更新时间:2022-10-15 12:03:37

您必须使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.