论坛首页 Java企业应用论坛

『出错』strut+hibernate+tomcat数据池配置问题

浏览 6010 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2006-04-10  
软件环境:
tomcat 5.5
struts 1.2
hibernate 3.0
配置文件:
hibernate配置文件:hibernate.cfg.xml
<?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="show_sql">true</property>
<property name="connection.datasource">java:comp/env/jdbc/struts</property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>

<mapping resource="user/UserForm.hbm.xml" />

</session-factory>

</hibernate-configuration>

错误提示信息:

Action 代码:UserAction.java
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {

UserForm Form = (UserForm) form;

// TODO Auto-generated method stub
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction ta = session.beginTransaction();  //此处便是提示中错误的位置
Form.setName(Form.getName());
Form.setAge(Form.getAge());
Form.setSex(Form.getSex());
session.save(Form);
ta.commit();
return mapping.findForward("success");

}


产生的错误:
exception

javax.servlet.ServletException: Cannot open connection
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:545)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:486)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

org.hibernate.exception.GenericJDBCException: Cannot open connection
org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:420)
org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:118)
org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1293)
user.UserAction.execute(UserAction.java:51)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)




你的分析:
上面的程序在不使用数据池的情况下一切正常。
不知道是何原因导致这个错误,在网上查找过,还是没有找到解决的方法,请大家赐教!
先谢谢了
   发表时间:2006-04-10  
建一个XML放在%TOMCAT_HOME%\conf\Catalina\localhost下面,内从如下:
jdbc/struts
<Context path="/struts" docBase="struts" debug="0">
<Resource name="jdbc/struts" auth="Container" type="javax.sql.DataSource"
  driverClassName="oracle.jdbc.driver.OracleDriver"
  url="jdbc:oracle:thin:@localhost:1521:doit"
  username="javablog"
  password="javablog"
  maxActive="20"
  maxIdle="3"
  removeAbandoned="true"
  maxWait="3000" />
</Context>
0 请登录后投票
   发表时间:2006-04-10  
加了还是一样,出现的错误也是一样的
0 请登录后投票
   发表时间:2006-06-14  
我建议你跟踪到源码里面,去发现问题!
0 请登录后投票
论坛首页 Java企业应用版

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