How do I check in my code whether a maximum limit of database connections have been reached?

Joe Sam Shirah

Use DatabaseMetaData.getMaxConnections() and compare to the number of connections currently open. Note that a return value of zero can mean unlimited or, unfortunately, unknown. Of course, driverManager.getConnection() will throw an exception if a Connection can not be obtained. For a little more discussion, see Can a single thread open up mutliple connections simultaneously for the same database and for same table?.