Get Only Usefull Css Code :
Month: September 2018
MySQL Connection Limit Issue resolve
StandardFollow following steps :
- vi /etc/my.cnf
- max_connections=2800
- save file
- service mysqld stop
- service mysqld start
- login into mysql and hit following command to check max connection limit :
- show variables like ‘max_connections’;
- Check “Threads_connected” variable to see total connections in use with following query :
- show status like ‘%onn%’;
Solution in java code to not to increase MySQL connections :
- In JDBC connection code strict to connection variable to not to create if already exists :
static Connection conn = null;
static Statement stmt = null;
constant cnst = new constant();
public dataBaseConnManager() {
if(conn==null)
{
conn = null;
stmt = null;
constant cnst = new constant();
// JDBC driver name and database URL
final String JDBC_DRIVER = “com.mysql.jdbc.Driver”;
final String DB_URL = “jdbc:mysql://localhost/”+cnst.dataBaseName;
final String USER = cnst.dataBaseUserName;
final String PASS = cnst.dataBasePassword;
try{
//STEP 2: Register JDBC driver
Class.forName(“com.mysql.jdbc.Driver”);
//STEP 3: Open a connection
conn = DriverManager.getConnection(DB_URL,USER,PASS);
//STEP 4: Execute a query
stmt = conn.createStatement();
}catch(SQLException se){
se.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
}
}