|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
手机用到的是用j2me所编出来的小程序。
之前事情的时分因为Oracle8i数据库常常呈现用户过量的毛病,因为数据量年夜,常常呈现ORA:12500毛病,但次要缘故原由是会见过量而引发的,厥后就用Java写了个复杂的用JDBC毗连来测试Oracle最年夜毗连数的程序.如今经常使用MySQL,以是又写了一个复杂的测试其最年夜毗连数的程序,在此先容给人人:- importjava.sql.Connection;
- importjava.sql.DriverManager;
- importjava.sql.Statement;
- importjava.sql.ResultSet;
- importjava.sql.SQLException;
- importjava.io.IOException;
- classtestMaxConn{
- publicstaticvoidmain(Stringargs[]){
- intcount=0;
- Connection[]conn=newConnection[1000];
- Statement[]stmt=newStatement[1000];
- ResultSet[]rs=newResultSet[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*FROMuser");
- while(rs[count].next()){
- //System.out.println(rs.getString(1)+
- " "+rs.getString(2));
- }
- System.out.print(count+" ");
- }
- }catch(SQLExceptionex1){
- System.out.println("
- "+ex1.toString());
- }catch(InstantiationExceptionex2){
- System.out.println("
- "+ex2.toString());
- }catch(ClassNotFoundExceptionex3){
- System.out.println("
- "+ex3.toString());
- }catch(IllegalAccessExceptionex4){
- System.out.println("
- "+ex4.toString());
- }finally{
- try{
- System.out.println("
- Systemhasopened
- "+count--+"MySQLconnections.
- PressEnterkey
- toclosetheconnections");
- System.in.read();
- System.out.println
- ("
- ClosetheConnections:");
- for(;count>=0;count--){
- rs[count].close();
- stmt[count].close();
- conn[count].close();
- System.out.print(count+" ");
- }
- }catch(SQLExceptionex){
- System.out.println
- ("
- Closeconnectionexception:"+ex.toString());
- }catch(IOExceptionio_ex){}
- }//endthefirst"try"
- }
- }
复制代码 java比较简单,没有C++的烦琐,但学习时最好有C++为基础.与JSP和SQL起应用,功能强大. |
|