[/code]Test.java    package com.zcq.dao;import java.util.Iterator;
import java.util.List;import org.hibernate.Session;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;import com.zcq.I.ZcqBB_I; public class Test {

public static void main(String[] args) {
 
ApplicationContext ctx=null;
  ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
    ZcqBB_I z=(ZcqBB_I)ctx.getBean("daoimp");
  List list=  z.findAll();
  
  
StringBuffer buff=new StringBuffer("<b>");

 for (Iterator iterator = list.iterator(); iterator.hasNext();) {
Asdas a= (Asdas) iterator.next();
buff.append("<zcqzcq>");
buff.append("<zcq>");
buff.append(a.getZcq());
buff.append("</zcq>"); 
buff.append("<bb>");
buff.append(a.getUnitno());
buff.append("</bb>"); 
buff.append("</zcqzcq>");
  
}
 
 buff.append("</b>");
 
 System.out.println(buff.toString());

}
}

解决方案 »

  1.   

    org.hibernate.exception.GenericJDBCException: Cannot open connection 
    不能打开连接,是不是数据库设置了限制什么的!
      

  2.   

    把dao里的查询方法替换成这个试试
    public List findAll() {
     return getHibernateTemplate().find("from Asdas");    
    }
      

  3.   

    出现这个 异常的愿意   总结一下 。 是因为 ctx=new ClassPathXmlApplicationContext("applicationContext.xml"); 这句话。  由于ajax 的速度太快。 所以就不停的new  导致出现异常
      

  4.   

    我觉得还是你的数据库连接问题。
    如果问题真如你在11楼所说,那么你可以试试如下方法
    public class Test {
        private ZcqBB_I z;
        public static void main(String[] args) {
              if(z == null){
                  ApplicationContext ctx=null;
                  ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
                  z=(ZcqBB_I) ctx.getBean("daoimp");
              }
              List list=  z.findAll();
              
              
                StringBuffer buff=new StringBuffer("<b>");
            
                 for (Iterator iterator = list.iterator(); iterator.hasNext();) {
                    Asdas a= (Asdas) iterator.next();
                    buff.append("<zcqzcq>");
                    buff.append("<zcq>");
                    buff.append(a.getZcq());
                    buff.append("</zcq>"); 
                    buff.append("<bb>");
                    buff.append(a.getUnitno());
                    buff.append("</bb>"); 
                    buff.append("</zcqzcq>");
              
                }
                 
                 buff.append("</b>");
                 
                 System.out.println(buff.toString());
            
        }
    }
      

  5.   

    呵呵,链接越大死得越快。是这样的,他每一次new都要创建一个spring的应用环境。spring又管理着数据源的创建,所以new一次就是连接池最小链接的个数创建,n次后,在前边的线程没有结束时,可能出现n× 最小链接数个连接 ,所以,问题的根源是控制创建spring的应用环境(qq:418148757)
      

  6.   

    13楼,可能看到问题的所在了,但是你这个写法,没什么意义。而且也解决不了问题。请在思考一下别的写法,或许吧应用环境存在一个static里边,问题应该就解决了,比如
    static ApplicationContext   ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
      

  7.   


    up
    应该放static里面,spring工厂只要1个就够了,不要创建那么多