In mysql the system variable "max_connections" has value 100. But i am trying to override this value programatically by pass key-value pair in jdbc connection string as "jdbc:mysql://localhost/test?maxConnections=3". But it seems like it is not reflecting any change. Here below I made maxConnection to 3 but still in below example I am able to create 40 connections. Note I have not closed connection in each iteration purposely.Just to see if the key value added in jdbc connection string is taking effect.If it takes effect then it should give exception of "Too many Connections"
See below code for reference:
public class JDBCOne {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
for(int i=1;i<=35;i++)
{
Connection conn = null;
Statement stmt = null;
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Connecting to database...:"+i);
conn = DriverManager.getConnection("jdbc:mysql://localhost/test?maxConnections=3", "root", "root");
stmt = conn.createStatement();
Integer id = null;
String name = null;
Double amount = null;
String sql = "SELECT * FROM emp where id=1";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
id = rs.getInt("id");
name = rs.getString("name");
amount = rs.getDouble("amount");
}
System.out.println("id-" + id);
}
System.out.println("Goodbye!");
}
}