Results 1 to 3 of 3
  1. #1
    ahmed30 is offline Member
    Join Date
    Jan 2011
    Posts
    6
    Rep Power
    0

    Default How To Solve "Too Many Connections" error message

    Hello ,

    I am keeping getting this error message
    Data source rejected establishment of connection, message from server: "Too many connections"
    and here is the Print Stacktrace

    Java Code:
    Data source rejected establishment of connection,  message from server: "Too many connections"
    com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection,  message from server: "Too many connections"
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
            at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
            at com.mysql.jdbc.Util.getInstance(Util.java:382)
            at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013)
            at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
            at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
            at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1116)
            at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2338)
            at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2371)
            at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2163)
            at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)
            at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
            at sun.reflect.GeneratedConstructorAccessor6.newInstance(Unknown Source)
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
            at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
            at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:378)
            at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
            at java.sql.DriverManager.getConnection(DriverManager.java:582)
            at java.sql.DriverManager.getConnection(DriverManager.java:185)
            at wezzara_project_2.bosta_class.get_images_no(bosta_class.java:195)
            at wezzara_project_2.bosta_class.getwared(bosta_class.java:85)
            at wezzara_project_2.wared_bosta.<init>(wared_bosta.java:45)
            at wezzara_project_2.edit_bosta.BeditActionPerformed(edit_bosta.java:225)
            at wezzara_project_2.edit_bosta.access$000(edit_bosta.java:16)
            at wezzara_project_2.edit_bosta$1.actionPerformed(edit_bosta.java:130)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
            at java.awt.Component.processMouseEvent(Component.java:6263)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3255)
            at java.awt.Component.processEvent(Component.java:6028)
            at java.awt.Container.processEvent(Container.java:2041)
            at java.awt.Component.dispatchEventImpl(Component.java:4630)
            at java.awt.Container.dispatchEventImpl(Container.java:2099)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
            at java.awt.Container.dispatchEventImpl(Container.java:2085)
            at java.awt.Window.dispatchEventImpl(Window.java:2475)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    SO when i did google the error messages , it says that this happened because i don't close my connections .

    so i did this
    Java Code:
      ArrayList<bosta_class> getwared()
        {
    
            con =getCon.getConnection();
            ResultSet getData  = null;
            
            
           try
            {
                stm = con.createStatement();
               /*Other Code  */
                    
                 
            }
            catch(Exception e)
            {
                System.out.println(e.getMessage());
                e.printStackTrace();
            }
            finally
            {
               try{if(stm!=null)stm.close();}catch(Exception e){System.out.println(e.getMessage());}
               try{if(con!=null)con.close();}catch(Exception e){System.out.println(e.getMessage());}
               
    
            }
            return data;
        }
    and i did that on every function i had ,

    Is that incorrect??

    btw , "getCon" is an object of another class that connects to mysql database.

    and also , i am using phpmyadmin . and my Max Connections is 151 .
    which i my connections didn't reach the 10 since i am closing the connection at every function.

    Thank You

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,797
    Rep Power
    19

    Default

    You've shown us getwared(), but the final exception comes from get_images_no().
    What about the code in there?

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Uhm, don't open so many connections? Close the connection as soon as you finish with it. And, maybe, maybe, after you've done both of these, increase the number of possible concurrent connections in the DB.

    IOW, use a pool, and then actually close the connections in the program (which essentially just returns it to the pool).

Similar Threads

  1. Error message "could not find the main class"
    By srwpchelp in forum New To Java
    Replies: 8
    Last Post: 12-23-2010, 09:15 PM
  2. How can I solve "void cannot be dereferenced" error?
    By fervent07 in forum New To Java
    Replies: 2
    Last Post: 04-05-2010, 08:54 PM
  3. How to solve this "Fixtures code" error exception?
    By makerror in forum New To Java
    Replies: 4
    Last Post: 12-02-2009, 02:45 AM
  4. Replies: 2
    Last Post: 12-02-2008, 11:06 AM
  5. Java Loader error message "UNC paths not supported"
    By Johnny562 in forum New To Java
    Replies: 1
    Last Post: 07-01-2008, 10:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •