kxbin
成功留给有准备的人
posts - 10,  comments - 35,  trackbacks - 0
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
 * 测试的最大连接数
 * oracle的默认连接数为135
 * Mysql的默认连接数为100
 * @author kxbin
 * 
 */
class testMaxConn {
int count = 0; // 连接数
Connection[] conn = new Connection[1000];
Statement[] stmt = new Statement[1000];
ResultSet[] rs = new ResultSet[1000];
/**
* 数据库连接方法(oracle)
*/
public void testOracleMaxConn() {
try {
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url = "jdbc:oracle:thin:@localhost:1521:compare";
for (count = 0; count < 135; count++) {
conn[count] = DriverManager.getConnection(url,"nxcompare", "64compare");
stmt[count] = conn[count].createStatement();
rs[count] = stmt[count].executeQuery("SELECT * FROM users");
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("\n系统打开的连接数"+ count--+ " oracle connections.\n请按回车按钮,进行关闭");
System.in.read();
System.out.println("\n闭关连接:");
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 关闭连接出现SQLException:"+ ex.toString());
} catch (IOException io_ex) {
System.out.println("\n 关闭连接出现IOException:"+ io_ex.toString());
}
}
}
/**
* 数据库连接方法(Mysql)
*/
public void testMysqlMaxConn() {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/tm?useUnicode=true&characterEncoding=GBK";
for (count = 0; count < 100; count++) {
conn[count] = DriverManager.getConnection(url,"root", "root");
stmt[count] = conn[count].createStatement();
rs[count] = stmt[count].executeQuery("SELECT * FROM userinfo");
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("\n系统打开的连接数"+ count--+ " MYSQL connections.\n请按回车按钮,进行关闭");
System.in.read();
System.out.println("\n闭关连接:");
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 关闭连接出现SQLException:"+ ex.toString());
} catch (IOException io_ex) {
System.out.println("\n 关闭连接出现IOException:"+ io_ex.toString());
}
}
}
/**
* 测试方法
* @param args
* @throws Exception
*/
public static void main(String args[]) throws Exception {
// new testMaxConn().testOracleMaxConn(); //测试Oracle默认最大连接数135
new testMaxConn().testMysqlMaxConn(); //测试MYSQL,默认最大连接数100
}
}
posted on 2011-09-16 11:00 kxbin 阅读(1536) 评论(0)  编辑  收藏 所属分类: ORACLEMYSQL

只有注册用户登录后才能发表评论。


网站导航:
 
你恨一个人是因为你爱他;你喜欢一个人,是因为他身上有你没有的;你讨厌一个人是因为他身上有你有的东西;你经常在别人面前批评某人,其实潜意识中是想接近他。

<2024年12月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿(5)

随笔档案

文章分类

文章档案

相册

收藏夹

J2EE

java技术网站

Linux

平时常去的网站

数据库

电影网站

网站设计

搜索

  •  

最新评论

阅读排行榜

评论排行榜