用java程序测试Mysql的最大衔接数[Java编程]
本文“用java程序测试Mysql的最大衔接数[Java编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
从前工作的时刻由于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)+
" "+rs.getString(2));
}
System.out.print(count+" ");
}
}catch(SQLException ex1){
System.out.println("
"+ex1.toString());
}catch(InstantiationException ex2){
System.out.println("
"+ex2.toString());
}catch(ClassNotFoundException ex3){
System.out.println("
"+ex3.toString());
}catch(IllegalAccessException ex4){
System.out.println("
"+ex4.toString());
}finally{
try{
System.out.println("
System has opened
"+count--+" MySQL connections.
Press Enter key
to close the connections");
System.in.read();
System.out.println
("
Close the Connections:");
for(;count>=0;count--){
rs[count].close();
stmt[count].close();
conn[count].close();
System.out.print(count+" ");
}
}catch(SQLException ex){
System.out.println
("
Close connection exception:"+ex.toString());
}catch(IOException io_ex){}
}//end the first "try"
}
}
以上是“用java程序测试Mysql的最大衔接数[Java编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |