按例子写了一个简单的Hibernate练习。在myeclipse中创建了一个java项目。添加了hibernate要使用的jar包。我的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="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
<property name="connection.username">text</property>
<property name="connection.password">123</property>
<property name="hbm2ddl.auto">create</property>
<property name="show_sql">true</property>
<mapping resource="text/lesson1/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>测试代码如下:
package util.hibernate;import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;import text.lesson1.User;public class Base { public static void main(String[] args) {
Configuration cfg = new Configuration();
cfg.configure();
SessionFactory sf = cfg.buildSessionFactory();
Session s = sf.openSession();
User user = new User();
user.setName("abc");
s.save(user);
s.close();
System.out.println("end");
}
}
在测试的时候出异常如下:
Exception in thread "main" org.hibernate.HibernateException: JDBC Driver class not found: oracle.jdbc.driver.OracleDriver
Caused by:java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
请问各位大虾我该把oracle的驱动程序classes12.jar放在什么位置(已经在classpath中配置了)。怎么才能排除这个错误呢?
<!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="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
<property name="connection.username">text</property>
<property name="connection.password">123</property>
<property name="hbm2ddl.auto">create</property>
<property name="show_sql">true</property>
<mapping resource="text/lesson1/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>测试代码如下:
package util.hibernate;import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;import text.lesson1.User;public class Base { public static void main(String[] args) {
Configuration cfg = new Configuration();
cfg.configure();
SessionFactory sf = cfg.buildSessionFactory();
Session s = sf.openSession();
User user = new User();
user.setName("abc");
s.save(user);
s.close();
System.out.println("end");
}
}
在测试的时候出异常如下:
Exception in thread "main" org.hibernate.HibernateException: JDBC Driver class not found: oracle.jdbc.driver.OracleDriver
Caused by:java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
请问各位大虾我该把oracle的驱动程序classes12.jar放在什么位置(已经在classpath中配置了)。怎么才能排除这个错误呢?
classes12.jar放的位置不对,或classpath没设置对1.如果是java项目,可以在项目文件夹上右键->属性,弹出eclipse属性对话框,选中左边一栏的java构建路径,再选择右边顶部的库(L)->添加库->用户库->点击“用户库”按钮->新建->写上库的名字(可随便填写)->点击“添加JAR”按钮->找到你的oracle驱动文件,全部选中->打开->确定->确认新建的库已经勾选,点“完成”2.如果是web项目,只要把oracle驱动文件拷贝到项目文件夹下WebRoot\WEB-INF\lib\中就行了;或者拷贝到Tomcat文件夹下common\lib\中也可以