Cause of Error:
Too many connections, too many logged-in users, too few MySQL connections configured, or some connections not shutting down, resulting in too many connections.
Solution to the problem:
Modify the MySQL my.ini configuration file, the Internet says: MySQL installation directory My.ini set in the number of concurrent connections is too small or the system is busy resulting in a full number of connections.
And the project is actually deployed on the Linux system, need to find MY.CNF configuration file, general in Etc/my.cnf, find this file, add the following line:
set-variable=max_connections=1000
set-variable=max_user_connections=500
set-variable=wait_timeout=200
Then restart MySQL to take effect.
net stop MySQL
net start MySQL
Max_connections: To set the maximum number of connections
Max_user_connections: Set maximum number of connections per user 500
Wait_timeout: Indicates that the idle connection will be closed after 200 seconds, but the connection to the work is not affected.
After restarting MySQL, use the following command to see if the changes were successful
# mysqladmin-uroot-p variables
Password:
You can see the following entry indicating the success of the modification
| max_connections | 1000
| max_user_connections | 500
| Wait_timeout | 200
Workaround Two:
Another possibility is that too many connections are open in the code, but forgetting to close in the finally block causes exceptions to be thrown when processing big data. There is no exception to this code.
try{ Conn=good.getconnection (); stmt = Conn.createstatement (resultset.type_scroll_insensitive, resultset.concur_updatable);String sql1="INSERT into cat_garbage values ('" +rs.getint ("id") +"', '" +rs.getint ("CID") +"', '" +rs.getstring ("Name") +"', '" +rs.getstring ("keyword") +"‘)"; Stmt.executeupdate (SQL1); } catch (sqlexception| classnotfoundexception| IOException e) { E.printstacktrace (); } finally { if (stmt!= null) Stmt.close (); if (conn!= null) Conn.close (); }
to remember to close resources such as rs,stmt,conn at any time, learn to use Finally, and in finally, these statements are bound to execute
Data Source rejected establishment of connection, message from server: "Too many connections"