Data Source rejected establishment of connection, message from server: "Too many connections" solution

Source: Internet
Author: User
Tags finally block stmt

An exception occurred in the internship

Com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:Data Source rejected establishment of Connection, message from server: "Too many connections"

See a lot of solutions on the Internet are basically said to modify the MySQL configuration file, open the MySQL installation directory open My.ini find Max_connections (in about 93rd line) By default is 1001-like settings to 500~1000 more appropriate, restart MySQL, This 1040 error will be solved.
max_connections=1000

But I tried, did not solve the exception, the reason for this exception is not only the one mentioned above, there is another possibility is that the code opened too many connections, but forgot to close in the finally block, resulting in the processing of large data, throw an exception. The following code will not have an exception.

   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 (); 
		}
   }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.