Hi Ajai,
  Here is the code:
the declaration part:
      private int limit=2;
      private int users=0;
      private Vector db_v;
      private Vector db_status;
      private int i;
The code in the doPost method:
           users++;
           if(users>limit)
             {
               if(!addconnection())
                  {
                    System.err.println("Failed to connect to the database");
                    return;
                  }
              }

            boolean found=false;
            i=0;
            String val=" ";
            while(!found)
               {
                  val=(String)db_status.elementAt(i);
                  if(val.equals("0"))
                    {
                       found=true;
                    }
                  else
                    {
                      i++;
                    }
                 }
             dbcon=(Connection)db_v.elementAt(i);
             db_status.setElementAt("1",i);


addconnection() is a public method which adds a new connection to the db_v
vector and increments limit.
  All this is from the Wrox server programming book.
  Thanks.
Vaijayanthi.


>From: ajaikumar peddapanga <[EMAIL PROTECTED]>
>Reply-To: "A mailing list for discussion about Sun Microsystem's Java
>        Servlet API Technology." <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: Re: ArrayIndexOutOfBoundsException
>Date: Thu, 18 May 2000 22:15:41 GMT
>
>send me that part of code  probably u messed up with the >= ...
>
>
>>From: Vaijayanthi Kolli <[EMAIL PROTECTED]>
>>Reply-To: "A mailing list for discussion about Sun Microsystem's Java
>>        Servlet API Technology." <[EMAIL PROTECTED]>
>>To: [EMAIL PROTECTED]
>>Subject: ArrayIndexOutOfBoundsException
>>Date: Thu, 18 May 2000 15:06:18 PDT
>>
>>Hi everybody,
>>          I am developing a website involving sevlets and an access
>>database.The UI is created using HTML.
>>   I am implementing Connection Pooling in that.
>>  I store a certain no. of connections(in a var. limit) in a vector and
>>keep
>>track of the number of users(in a var. users).Once the number of users
>>exceeds the limit(users>limit)I increase the limit by adding one more
>>connection to the vector.
>>   I have set the initial value for limit as 2 and that of users as 0.
>>   When I try to access the servlet from two browsers simultaneously,and
>>the
>>value for users is 2,I get the following error:
>>
>>Error: 500
>>
>>Internal Servlet Error:
>>
>>java.lang.ArrayIndexOutOfBoundsException: 2 >= 2
>>        at java.util.Vector.elementAt(Compiled Code)
>>        at db1servlet.doPost(Compiled Code)
>>        at javax.servlet.http.HttpServlet.service(HttpServlet.java:747)
>>        at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
>>        at
>>com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:140)
>>        at
>>com.sun.web.core.InvokerServlet.service(InvokerServlet.java:169)
>>        at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
>>        at
>>com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:140)
>>        at com.sun.web.core.Context.handleRequest(Context.java:375)
>>        at com.sun.web.server.ConnectionHandler.run(Compiled Code)
>>
>>  Can anybody tell me what is causing this problem?
>>Secondly,what is the default capacity of a vector?
>>
>>Thanks in advance.
>>Vaijayanthi.
>>
>>
>>________________________________________________________________________
>>Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
>>
>>___________________________________________________________________________
>>To unsubscribe, send email to [EMAIL PROTECTED] and include in the
>>body
>>of the message "signoff SERVLET-INTEREST".
>>
>>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>>Resources: http://java.sun.com/products/servlet/external-resources.html
>>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
>________________________________________________________________________
>Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to