当前位置: 首页 > 图文教程 > 数据库 > MSSQL > Mysql的最大连接数怎样用java程序测试

MSSQL
SQl 跨服务器查询语句
sql2005 HashBytes 加密函数
防止SQLSERVER的事件探查器跟踪软件
Excel导入Sqlserver数据库脚本
sql cast,convert,QUOTENAME,exec 函数学习记录
select into 和 insert into select 两种表复制语句
sqlserver 日志恢复方法(搞定drop和truncate)
海量数据库查询语句
DBCC CHECKIDENT 重置数据库标识列从某一数值开始
MSSQL 数据库同步教程
sql 语句中的 NULL值
判断一个表的数据不在另一个表中最优秀方法
SQL货币数字转英文字符语句
executesql 存储过程
sql 查询结果合并union all用法_数据库技巧
SQLServe 重复行删除方法
SQLServer 数据修复命令DBCC一览
SQLSERVERS 数据整理方法
根据多条件查询临时表 想得到不同结果集的方法
sqlServer 获取汉字字串的拼音声母

MSSQL 中的 Mysql的最大连接数怎样用java程序测试


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-17   浏览: 43 ::
收藏到网摘: n/a

以前工作的时候由于Oracle8i数据库经常出现用户过多的错误,由于数据量大,经常出现ORA:12500错误,但主要原因是访问过多而引起的,后来就用Java写了个简单的用JDBC连接来测试Oracle最大连接数的程序.现在常用MySQL,所以又写了一个简单的测试其最大连接数的程序,在此介绍给大家:

以下为引用的内容:

import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.Statement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.io.IOException;
 
 class testMaxConn{
   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/MySQL", "root", "");
      stmt[count]=conn[count].createStatement();
      rs[count]=stmt[count].executeQuery
("SELECT * FROM user");
      while (rs[count].next()){
  //System.out.println(rs.getString(1)+
"\t "+rs.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"
   }
 }