Fosdccf.blog.chinaunix.net
sdccf
全部博文(19283)
Linux酷软(214)
tmp(0)
PostgreSQL(93)
Solaris(383)
AIX(173)
SCOUNIX(575)
DB2(1005)
Shell(386)
C/C++(1187)
MySQL(1750)
Sybase(465)
Oracle(3695)
Informix(548)
HP-UX(0)
IBM AIX(2)
Sun Solaris(0)
BSD(1)
Linux(8597)
SCO UNIX(23)
2011年(1)
2009年(125)
2008年(19094)
2007年(63)
clifford
linky521
曾德标
fengzhan
leon_yu
mcuflowe
yt200902
guanyuji
GY123456
snow888
carlos94
丸喵喵
sean229
cxunix
可怜的猪
cqxc413
xzzgege
wb123456
分类: Mysql/postgreSQL
2008-03-25 00:03:46
以前工作的时候由于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" } }
以前工作的时候由于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" } }
上一篇:轻松解决:mysql数据库连接过多的错误
下一篇:解析:MySQL 5.0.16乱码问题的解决方法
登录 注册