1

I'm currently writing a program in java where I often get data from the MySQL database, with a JDBC driver. At first I tried to close the connection every time I ran the program to test it, but it gave an error at that line. I left the 'connection.close()' line out and it worked, which at the time was good enough for me.

Unfortunatly that backfired, because now I can't run the program anymore. It gives the following error.

Data source rejected estabilishment of connection, message from server: "Too many connections" 

I honestly have no idea how to fix this. Another related app in Visual Studio rebuild the database every time I run that, so I don't think that's a problem. I deleted the databse in my java editor, Netbeans, and re-imported it, but that didn't solve it either. My googling skills have failed me as well, even the question on stackoverflow didn't seem to work.

Any help would be much appreciated

7
  • 5
    Close your connections. Commented Apr 15, 2014 at 21:28
  • On an different note wrt how to "reset" the error: make sure there are no background processes running with open connections (connections will be closed when the programs are terminated, but background programs are still running) and, if all else fails, forcibly have MySQL eject it's connections (I believe this means "restart" in MySQL terms). Commented Apr 15, 2014 at 21:30
  • What is the error that connection.close() is throwing? Commented Apr 15, 2014 at 21:32
  • as a practice, you should close the connection if it does not requires to be open. btw check your mysql configuration to see how many concurrent connections do you have. Commented Apr 15, 2014 at 21:33
  • Yeah, if I knew how to close the connections, we wouldn't be here huh? I tried to use the SHOW PROCESSLIST command in MySQL, but I only saw 1 connection in there, mine. Also I think I'm desperate enough to try the last option, go to 'Services' of my computer and restart the MySQL service? Commented Apr 15, 2014 at 21:34

2 Answers 2

2

You can use connection pooling.
A cache of database connections maintained in the database's memory so that the connections can be reused when the database receives future requests for data.
Connection pools are used to enhance the performance of executing commands on a database.
Refer this : http://en.wikipedia.org/wiki/Connection_pool

Sign up to request clarification or add additional context in comments.

Comments

1

Since the connections were never closed by your program, they are staying open and using up the connection limit for the MySQL server. Even resetting the database won't necessarily eject or end those connections to the MySQL service, because the connections are attached to the server, not the database file. I would just restart the MySQL server, which will eject and close all current connections, as user2864740 suggested.

In order to fix your problem with the program throwing an error every time you try to close a connection, like Matt K said, you are going to need to post the error you are getting. You certainly need to close the connections in your program.

1 Comment

mmm that doesn't seem to do the trick tbh. I restarted the MySQL services, but I still get the error. I'm going to try and debug the program, but it for some reason my java editor seems to be acting weird with that :/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.