【发布时间】:2011-09-16 17:10:49
【问题描述】:
在使用 hibernate 连接 MySQLDB 并添加数据时,我遇到了一个非常奇怪的问题。
这是我得到的错误:
找不到 JDBC 驱动程序类: com.mysql.jdbc.Driver
这就是我的 hibernate.cfg.xml 的样子
<!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>
我不明白为什么我在导航到应用程序时看到 500 错误;它说找不到驱动程序。
HTTP 错误 500
访问 /fpa-webapp/ 时出现问题。 原因:
Exception constructing service 'ValueEncoderSource': Error invoking服务生成器方法 org.apache.tapestry5.services.TapestryModule.buildValueEncoderSource(地图, InvalidationEventHub) (在 TapestryModule.java:2287)(用于服务 'ValueEncoderSource'): 调用错误 服务贡献法 org.apache.tapestry5.hibernate.HibernateModule.contributeValueEncoderSource(MappedConfiguration, 布尔值,HibernateSessionSource, 会话,TypeCoercer,PropertyAccess, LoggerSource): 异常构造 服务“休眠会话源”: 调用服务生成器方法时出错 org.apache.tapestry5.hibernate.HibernateCoreModule.buildHibernateSessionSource(记录器, 列表,RegistryShutdownHub)(在 HibernateCoreModule.java:123)(对于 服务'HibernateSessionSource'): 找不到 JDBC 驱动程序类: com.mysql.jdbc.Driver
我确定驱动程序在类路径中。
可能是什么?
【问题讨论】:
-
“我确定驱动程序在类路径中。” 你有多确定? :)
-
它是网络应用还是独立应用,您是如何提供类路径的?
-
这是一个网络应用程序。我确定驱动程序在那里,因为我打开了项目的类路径文件,我看到了带有驱动程序名称的 .xml 标记。
-
如果您从 ServletContextInitializer 实现成功运行此代码,我会相信您:尝试 { class.forName("com.mysql.jdbc.Driver").newInstance(); System.out.println("你赢了") ; } catch (Throwable t) { System.out.println("你撒谎了:"+t); }
-
你能告诉我从 servletcontextInitializer 运行是什么意思吗?因为使用当前配置(见上文),我收到 HTTP 错误 500,无法访问该应用程序。你的意思是从其他地方运行它对吧?
标签: java mysql hibernate driver