java 测试mysql 最大连接

package com.mschn.elife;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.io.IOException;

public class testMaxActive {
    public static void main(String args[]){
     int count=0;
     Connection []conn=new Connection[1000];
     Statement  []stmt =new Statement[1000];
     ResultSet  []rs =new ResultSet[1000];
    try{
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            for(count=0;count<300;count++){
                  conn[count] = DriverManager.getConnection("jdbc:mysql://localhost/student", "root", "root");
                  stmt[count]=conn[count].createStatement();
                  rs[count]=stmt[count].executeQuery("SELECT * FROM ckf_staff");
/*                  while (rs[count].next()){
                      System.out.println(rs[count].getString(1)+"\t "+rs[count].getString(2));  
                  }*/
                  System.out.print(count+"\t");
             }
    }catch(SQLException ex1){
      System.out.println("\n"+ex1.toString());
    }catch(InstantiationException ex2){
      System.out.println("\n"+ex2.toString());
    }catch(ClassNotFoundException ex3){
      System.out.println("\n"+ex3.toString());
    }catch(IllegalAccessException ex4){
      System.out.println("\n"+ex4.toString());
    }finally{
      try{
        System.out.println("\nSystem has opened"+count--+" MySQL connections.\nPress Enter key to close the connections");
        System.in.read();
        System.out.println("\nClose the Connections:");
        for(;count>=0;count--){
         rs[count].close();
         stmt[count].close();
         conn[count].close();
         System.out.print(count+"\t");
        }
      }catch(SQLException ex){
       System.out.println("\n Close connection exception:"+ex.toString());
      }catch(IOException io_ex){}
    }//end the first "try"
   }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值