package org.kodejava.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
public class MaxConcurrentConnection {
private static final String URL = "jdbc:mysql://localhost/kodejava";
private static final String USERNAME = "kodejava";
private static final String PASSWORD = "s3cr*t";
public static void main(String[] args) {
try (Connection connection =
DriverManager.getConnection(URL, USERNAME, PASSWORD)) {
DatabaseMetaData metadata = connection.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 e) {
e.printStackTrace();
}
}
}
The result of the code snippet above:
Maximum Connection = 0
Maven Dependencies
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.1.0</version>
</dependency>
Latest posts by Wayan (see all)
- How do I create a string of repeated characters? - September 1, 2023
- How do I convert datetime string with optional part to a date object? - August 28, 2023
- How do I split large excel file into multiple smaller files? - April 15, 2023