Problems using Hibernate - JDBC Driver class not found: com.mysql.jdbc.Driver
I have a really strange issue when using hibernate to connect to a MySQLDB and add data.
This is the error I get:
JDBC Driver class not found: com.mysql.jdbc.Driver
This is how my hibernate.cfg.xml looks like
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/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/fpa-webapp</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="hbm2ddl.auto">update</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
</session-factory>
</hibernate-configuration>
I dont understand why I see a 500 Error when I navigate to the application; it says that the driver is not found.
HTTP ERROR 500
Problem accessing /fpa-webapp/. Reason:
Exception constructing service 'ValueEncoderSource': Error invoking
service builder method org.apache.tapestry5.services.TapestryModule.buildValueEncoderSource(Map, InvalidationEventHub) (at TapestryModule.java:2287) (for service 'ValueEncoderSource'): Error invoking service contribution method org.apache.tapestry5.hibernate.HibernateModule.contributeValueEncoderSource(MappedConfiguration, boolean, HibernateSessionSource, Session, TypeCoercer, PropertyAccess, LoggerSource): Exception constructing service 'HibernateSessionSource': Error invoking service builder method org.apache.tapestry5.hibernate.HibernateCoreModule.buildHibernateSessionSource(Logger, List, RegistryShutdownHub) (at HibernateCoreModule.java:123) (for service 'HibernateSessionSource'): JDBC Driver class not found:开发者_如何转开发 com.mysql.jdbc.Driver
I'm sure the driver is in the class path.
What it could be?
Your driver is not on the classpath.
There are two ways to ensure it's on the classpath:
- Add it to the global lib directory. For Tomcat this is
TOMCAT_HOME/lib
. - Include it in the war.
It depends on your requirements which you use.
If you're going to use Tomcat to manage the connection pool, you'll need to add it to the TOMCAT_HOME/lib
and instead of defining your datasource directly in the hibernate configuration, you'll reference it via jndi.
The only plausible explanation is that the Driver
class is not on the CLASSPATH.
Check to make sure that the mysql-connector-java (or other relevant) jar is indeed in a place where it will get loaded. If you're 100% positive that it is, it might help to provide more information about how you know the class is being loaded, so that we can identify other possible causes.
精彩评论