Connection conn=null; 
try{ String url="jdbc:mysql://127.0.0.1:3306/test?characterEncoding=GBK&useUnicode=TRUE&user=root&password=";
            Class.forName("org.gjt.mm.mysql.Driver");
            
            for(int i=0;i<100;i++)
            {
            conn=DriverManager.getConnection(url);
            System.out.println("conn.isClosed()?" + conn.isClosed());
            

            conn.close();
            
            System.out.println("conn.isClosed()?" + conn.isClosed());
            conn=null;
    }
}catch(Exception ex){
System.out.println();
}finally{ try{
if(conn!=null){
conn.close();
conn=null;
}
}catch(Exception ex){
System.out.println(ex.toString());
} }题

解决方案 »

  1.   

    show VARIABLES like 'max_connections'; 显示最大连接数设置为10
    show PROCESSLIST; 显示当前连接用户为root(只有一条记录)
    show status like 'connections'; 显示当前连接已经超过1000个,其实每次都有close,但connections却没有减少在这种情况下连接数据库,检索记录的页面显示仍然正常,没有出现连接不成功或速度明显慢的情况。
    这种现象如何解释?难道max_connections设置不起作用?
      

  2.   

    用过其他程序连接MYSQL没有问题,比如C#,
    甚至直接使用java test 来调用class代码都没有出现过connections增加的情况。
    但是,如果把class放到eclips中或者将JSP放到TOMCAT中,就会出现。
      

  3.   

    程序有地方出错 没有执行到清除连接建议换用连接池 JDBC直连还是有弊端的
      

  4.   

    用过其他程序连接MYSQL没有问题,比如C#,
    甚至直接使用java test 来调用class代码都没有出现过connections增加的情况。
    但是,如果把class放到eclips中或者将JSP放到TOMCAT中,就会出现。
    ----------------------------------------------------------------------------------
    检查下驱动在不同环境下用的是不是一样的