论坛首页 Java企业应用论坛

help为什么连不上db(tomcat5.0+hibernate)

浏览 11202 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2004-01-08  
看hibernate_reference(2.1)第一章 mm驱动在web-inf/lib中了 结果错误如下:
net.sf.hibernate.JDBCException: Cannot open connection: Cannot load JDBC driver class 'org.gjt.mm.mysql.Driver'
	net.sf.hibernate.impl.SessionFactoryImpl.openConnection(SessionFactoryImpl.java:399);
	net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:2914);
	net.sf.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:39);
	net.sf.hibernate.transaction.JDBCTransactionFactory.beginTransaction(JDBCTransactionFactory.java:22);
	net.sf.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1981);
	test.hibernate.dao.CatDao.createCat(Unknown Source);
	org.apache.jsp.test_jsp._jspService(test_jsp.java:51);
   发表时间:2004-01-08  
test.jsp
<%@ page import="java.util.*,test.hibernate.dao.*,test.hibernate.po.*,test.hibernate.util.*"%>
<%
	Cat cat = new Cat();;
	cat.setName("Princess");;
	cat.setSex('F');;
	cat.setWeight(7.4f);;
	CatDao cdao = new CatDao();;
	cdao.createCat(cat);;
%>
0 请登录后投票
   发表时间:2004-01-08  
CatDao.java
package test.hibernate.dao;
import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;
import test.hibernate.util.*;
import test.hibernate.po.*;
public class CatDao{
	public void createCat(Cat cat);throws HibernateException{
		Session session = MySessionFactory.currentSession();;
	    Transaction	tx = session.beginTransaction();;
		session.save(cat);;
		tx.commit();;
		MySessionFactory.closeSession();;
	}
}
0 请登录后投票
   发表时间:2004-01-08  
好像非.jar的驱动不会自动加入动态库载入,可以查一下tomcat的启动日志
0 请登录后投票
   发表时间:2004-01-08  
package test.hibernate.util;
import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;
public class MySessionFactory {
	private static final SessionFactory sessionFactory;
	static {
		try {
			sessionFactory = new Configuration();.configure();.buildSessionFactory();;
		} catch (HibernateException ex); {
			throw new RuntimeException("Exception building SessionFactory: " + ex.getMessage();, ex);;
		}
	}
	public static final ThreadLocal session = new ThreadLocal();;
	public static Session currentSession(); throws HibernateException {
		Session s = (Session); session.get();;
		// Open a new Session, if this Thread has none yet
		if (s == null); {
			s = sessionFactory.openSession();;
			session.set(s);;
		}
		return s;
	}
文档中的SessionFactory我就改了一下包名
0 请登录后投票
   发表时间:2004-01-08  
messup 写道
好像非.jar的驱动不会自动加入动态库载入,可以查一下tomcat的启动日志


mysql-connector-java-3.0.9-stable-bin.jar
0 请登录后投票
   发表时间:2004-01-08  
看你所报异常,就是不能正确装载mysql driver,请仔细检查你的driver,最好将其引入至系统classpath中。
0 请登录后投票
   发表时间:2004-01-08  
Dennis 写道
看你所报异常,就是不能正确装载mysql driver,请仔细检查你的driver,最好将其引入至系统classpath中。


应该不是的,我现在放在%tomcat 用的jdk%/jre/lib/ext下还是同样的问题
0 请登录后投票
   发表时间:2004-01-08  
根据错误,偶觉得应该只要解决栽入mysql driver就ok了。
是不是driver所在的webapp因为其它原因出错,然后导致webapp没有完全正确载入影响了mysql driver?
建议看一下tomcat启动日志,是否有相应的信息。
0 请登录后投票
   发表时间:2004-01-08  
dugout 写道
Dennis 写道
看你所报异常,就是不能正确装载mysql driver,请仔细检查你的driver,最好将其引入至系统classpath中。


应该不是的,我现在放在%tomcat 用的jdk%/jre/lib/ext下还是同样的问题
我说的是放至操作系统的classpath里,你用的什么开发环境?如果用了类似Jbuilder的IDE,还需在IDE里将该驱动引入.
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics