测试Oracle最大连接数

package com.jxtech;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class TestConn {
    public static void main(String args[]) {
        int max = 500;
        Connection[] connection = new Connection[max];
        Statement[] statement = new Statement[max];
        ResultSet[] resultSet = new ResultSet[max];
        int i = 0;
        try {
            String driverName = "oracle.jdbc.driver.OracleDriver";
            Class.forName(driverName);
            String url = "jdbc:oracle:thin:@10.152.3.140:1521:EAMDB2";
            for (i = 0; i < max; i++) {
                System.out.println("连接到oracl成功!----" + i);
                connection[i] = DriverManager.getConnection(url, "soe", "soe");
                statement[i] = connection[i].createStatement();
                resultSet[i] = statement[i].executeQuery("select * from orders");
            }
        } catch (Exception e) {
            System.out.print("失败:" + i);
            e.printStackTrace();
        } finally {
            for (int x = 0; x < i; x++) {
                try {
                    System.out.println("关闭oracl成功!----" + x);
                    resultSet[x].close();
                    statement[x].close();
                    connection[x].close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                 
            }
        }
    }
}

猜你喜欢

转载自awen7916.iteye.com/blog/2220083