我在做一个SSH的项目,属于功能升级:
写了一个业务逻辑的class Biz,对相关的表做了ORMAP,写了一个测试类继承Testcase
服务器用tomcat,datasource配置了连接池用测试类直接测试,一切正常,但是部署到tomcat就报错:#  Exception occurred while logging on
org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: Cannot open connection; uncategorized SQLException for SQL [???]; SQL state [null]; error code [0]; Connections could not be acquired from the underlying database!; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!

解决方案 »

  1.   

     Cannot open connection
      

  2.   

    用junit测试和部署有什么区别?为什么一个可以,一个报错?
      

  3.   

    可能是有什么地方Session没关闭,造成连接数超过最大限制
    http://topic.csdn.net/u/20090609/21/213a1d6b-86ee-408f-8089-b311f535961a.html
      

  4.   

    数据库服务器一直up,要不然怎么用junit测试啊
      

  5.   

    这是applicationContext.xml的datasource,sessionFactory的配置:
    <bean id="dataSource"  
            class="com.mchange.v2.c3p0.ComboPooledDataSource"  
            destroy-method="close">
            <property name="driverClass">
                <value>oracle.jdbc.driver.OracleDriver</value>  
            </property>  
            <property name="jdbcUrl">  
                <value>jdbc:oracle:thin:@10.11.100.211:1521:prswdd</value>  
            </property>  
            <property name="user">  
                <value>calparis</value>  
            </property>  
            <property name="password">  
                <value>calparis</value>  
            </property>   
            <property name="minPoolSize">  
                <value>3</value>
            </property> 
            <property name="maxPoolSize">  
                <value>20</value>
            </property> 
            <property name="initialPoolSize">  
                <value>3</value>
            </property>
            <property name="maxIdleTime">  
                <value>60</value>
            </property> 
            <property name="maxStatements">  
                <value>3</value>
            </property>
            <property name="testConnectionOnCheckout">  
                <value>true</value>
            </property>  
         </bean>  <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">  
                   <ref local="dataSource" />
            </property>
    <property name="configLocation"
    value="classpath:hibernate.cfg.xml">
    </property>
    </bean>这是hibernate.cfg.xml的SessionFactory的补充配置:
    <session-factory>
        <property name="myeclipse.connection.profile">
    Cal_Paris3
    </property>
    <property name="dialect">
    org.hibernate.dialect.Oracle9Dialect
    </property>
    <property name="show_sql">true</property>
    <property name="hibernate.generate_statistics">true</property>
    <property name="hibernate.connection.release_mode">auto</property>
    ...
    ......  
    </session-factory>
      

  6.   

    这是DAO中连数据库的函数,getHibernateTemplate().find(queryString) 就会抛出异常。
    public String getMaxVendorId() {
    log.debug("geting max vendor ID");
    try {
    String queryString = "select max(vendor.vendorId) from CalibVendor vendor";
    List<String> li =  getHibernateTemplate().find(queryString);
    if(li.get(0)==null)
    {
    return "0";
    }
    else
    {
    return li.get(0);
    }
    } catch (RuntimeException re) {
    log.error("geting max vendor ID failed", re);
    throw re;
    }
    }
      

  7.   

    不嫌弃的话,把项目发到我邮箱[email protected],明天晚上我下班回来看一下
      

  8.   

    用hibernateTemplate应该不用手动管理session吧
      

  9.   

    tomcat和数据库是在同一服务器?
      

  10.   

    把tomcat 配置一下。
    invwork
      

  11.   

    ssh中只用过spring,通过对spring的经验,我个人觉得tomcat有问题大多都是配置文件中有问题。
      

  12.   

    建议还是裸奔下tomcat和带个简单的jdbc调试下.