myeclipse javaWeb应用hibernate出错
不是报我自写的hibernate类未初始化,就是报java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 驱动没找到。但是我在该工程里写了另一个非javaWeb类测试能通过。。。 很是郁闷。。 忘大侠帮忙
这是自己写的hibernate类
package com.hibernate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public final class hibernateUtil {
//用私有的构造方法,禁止其他地方新建hibbernate对象//不能继承。。 也不能实例化
private static SessionFactory sessionfactory = null;
private hibernateUtil(){
}//构造函数
static{ //保证只执行一次
Configuration config = new Configuration();
config.configure();//里面的参数为hibernate.cfg.xml文件。。默认
sessionfactory = config.buildSessionFactory();
}//保证了sessionfactory不为空
//获得sessionFactory对象
public static SessionFactory getSessionfactory() {
return sessionfactory;
}
public static Session getSession(){
return sessionfactory.openSession();
}
}
配置文件
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="connection.username">root</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/student
</property>
<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">UTF-8</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="myeclipse.connection.profile">student</property>
<property name="connection.password">aijian</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<mapping resource="hibernate/User.hbm.xml" />
<mapping resource="hibernate/Teacherinformation.hbm.xml" />
<mapping resource="hibernate/Studentinformation.hbm.xml" />
<mapping resource="hibernate/StudentTeacherClass.hbm.xml" />
<mapping resource="hibernate/Teacheclass.hbm.xml" />
</session-factory>
</hibernate-configuration>
相应的表配置我就不贴了