Jump to content

Recommended Posts

Posted

I have a war file basically servlet and jsp pages. A new online based shopping website. I get mysql max user connections error in jdbc.

 

In my website I am able to only send data to sql from two simultaneous pages.

 

My minimum requirements is to support atleast 20 users at same time. Can anyone please increase the number of active connections in .conf file of tomcat

 

post-104745-0-00926800-1517142918_thumb.png

Posted

Make sure you close all mysql connections as soon as you are done with them. Do something like this:

Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;

try {
    // Do stuff
    ...

} catch (SQLException ex) {
    // Exception handling stuff
    ...
} finally {
    if (rs != null) {
        try {
            rs.close();
        } catch (SQLException e) { /* ignored */}
    }
    if (ps != null) {
        try {
            ps.close();
        } catch (SQLException e) { /* ignored */}
    }
    if (conn != null) {
        try {
            conn.close();
        } catch (SQLException e) { /* ignored */}
    }
}
Sites that close their mysql connections can handle thousands of visitors. Sites that use persistent connections can generally only serve a very small number of visitors. The default in java is to treat all connections as persistent unless you code it otherwise. The limit is in place to prevent one user from blocking anyone else from connecting to mysql.
Posted

Well, if you can't get your code to close the connections you can always try a different language. For instance you could have the remote java application connect to a php script on the server. Closing mysql connections in php is pretty easy. The other option I can think of is to get a vps https://www.heliohost.org/partners/vps that way you have the whole server to yourself and java can open howeveer hundreds of connections as it wants to. Any shared host you find (even paid ones) will have a limit on the number of simultaneous connections.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...