When working previously because the Oracle8i database often appears the user too many errors, due to the large amount of data, often appear ora:12500 error, but the main reason is too much access caused, Later, Java wrote a simple JDBC connection to test the number of Oracle connections to the program. Now common MySQL, so also write a simple test its maximum number of connections to the program, introduced here to everyone:
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 ("\ Close Connection exception:" +ex.tostring ()); }catch (IOException io_ex) {}}//end the ' I ' Try '}}