精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2004-01-08
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); 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间: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);; %> |
|
返回顶楼 | |
发表时间: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();; } } |
|
返回顶楼 | |
发表时间:2004-01-08
好像非.jar的驱动不会自动加入动态库载入,可以查一下tomcat的启动日志
|
|
返回顶楼 | |
发表时间: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我就改了一下包名 |
|
返回顶楼 | |
发表时间:2004-01-08
messup 写道 好像非.jar的驱动不会自动加入动态库载入,可以查一下tomcat的启动日志
mysql-connector-java-3.0.9-stable-bin.jar |
|
返回顶楼 | |
发表时间:2004-01-08
看你所报异常,就是不能正确装载mysql driver,请仔细检查你的driver,最好将其引入至系统classpath中。
|
|
返回顶楼 | |
发表时间:2004-01-08
Dennis 写道 看你所报异常,就是不能正确装载mysql driver,请仔细检查你的driver,最好将其引入至系统classpath中。
应该不是的,我现在放在%tomcat 用的jdk%/jre/lib/ext下还是同样的问题 |
|
返回顶楼 | |
发表时间:2004-01-08
根据错误,偶觉得应该只要解决栽入mysql driver就ok了。
是不是driver所在的webapp因为其它原因出错,然后导致webapp没有完全正确载入影响了mysql driver? 建议看一下tomcat启动日志,是否有相应的信息。 |
|
返回顶楼 | |
发表时间:2004-01-08
dugout 写道 Dennis 写道 看你所报异常,就是不能正确装载mysql driver,请仔细检查你的driver,最好将其引入至系统classpath中。
应该不是的,我现在放在%tomcat 用的jdk%/jre/lib/ext下还是同样的问题 |
|
返回顶楼 | |