Below Java code shows how to get Max concurrent connections to database –
[java]
/****************************************************************************************
* Created on 05-2011 Copyright(c) https://kodehelp.com All Rights Reserved.
****************************************************************************************/
package com.kodehelp.javasql;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
* Created by https://kodehelp.com
* Date: 5/9/11
*/
public class GetMaxConnections {
public static void main(String args[]) throws SQLException, ClassNotFoundException {
Connection conn =null;
try{
final String driver = "oracle.jdbc.driver.OracleDriver";
final String url = "jdbc:oracle:thin:@HOST:PORT:SID";
final String USERNAME = "USERNAME";
final String PASSWORD = "PASSWORD";
Class.forName(driver); // load Oracle driver
conn = DriverManager.getConnection(url, USERNAME, PASSWORD);
DatabaseMetaData metadata = conn.getMetaData();
//
// Get the information of maximum concurrent connection to the
// database. The maximum number of active connections possible at
// one time; a result of zero means that there is no limit or the
// limit is not known
//
int maxConnection = metadata.getMaxConnections();
System.out.println("Maximum Connection = " + maxConnection);
}catch (SQLException sqlEx){
throw sqlEx;
}catch (ClassNotFoundException cnfEx){
throw cnfEx;
}finally{
if(conn!=null){
conn.close();
}
}
}
}
[/java]