最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 正文

Java测试Oracle连接数

来源:动视网 责编:小OO 时间:2025-10-01 20:43:18
文档

Java测试Oracle连接数

用Java写了个简单的用JDBC连接来测试Oracle最大连接数的程序,当连接数达到600多个时,会报下面的错误:java.sql.SQLException:Listenerrefusedtheconnectionwiththefollowingerror:ORA-12518,TNS:listenercouldnothandoffclientconnectionTheConnectiondescriptorusedbytheclientwas:10.16.0.31:1521:polyfilm类
推荐度:
导读用Java写了个简单的用JDBC连接来测试Oracle最大连接数的程序,当连接数达到600多个时,会报下面的错误:java.sql.SQLException:Listenerrefusedtheconnectionwiththefollowingerror:ORA-12518,TNS:listenercouldnothandoffclientconnectionTheConnectiondescriptorusedbytheclientwas:10.16.0.31:1521:polyfilm类
用Java写了个简单的用JDBC连接来测试Oracle最大连接数的程序,

当连接数达到600多个时,会报下面的错误:

java.sql.SQLException: Listener refused the connection with the following error:

ORA-12518, TNS:listener could not hand off client connection The Connection descriptor used by the client was:10.16.0.31:1521:polyfilm

类的代码如下:

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.Statement;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.io.IOException;

public class TestMaxConnection {

    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("oracle.jdbc.driver.OracleDriver").newInstance();

            for (count = 0; count < 990; count++) {

                conn[count] = DriverManager.getConnection("jdbc:oracle:thin:@10.16.0.31:1521:polyfilm", 

                        "shilin", "shilin");

                stmt[count] = conn[count].createStatement();

                rs[count] = stmt[count].executeQuery("SELECT * FROM ad_user");

                while (rs[count].next()) {

                    //System.out.println(rs[count].getString(1) + "\ "+ rs[count].getString(2));

                }

                System.out.print(count + "\");

            }

        } 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--

                    + " 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 + "\");

                }

            } catch (SQLException ex) {

                System.out.println("\\n Close connection exception:"+ ex.toString());

            } catch (IOException io_ex) {

            }

        }//end the first "try"

    }

}

文档

Java测试Oracle连接数

用Java写了个简单的用JDBC连接来测试Oracle最大连接数的程序,当连接数达到600多个时,会报下面的错误:java.sql.SQLException:Listenerrefusedtheconnectionwiththefollowingerror:ORA-12518,TNS:listenercouldnothandoffclientconnectionTheConnectiondescriptorusedbytheclientwas:10.16.0.31:1521:polyfilm类
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top