You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Micael <ca...@harbornet.com> on 2003/05/20 18:02:19 UTC

Re: DBCP Connection Pool is slower than setting up direct connection to mySql

What is the question, Richie?  I just JNDI with DBCP and have no speed issues.

Micael

At 08:50 AM 5/20/03 -0700, you wrote:
>Hello all,
>Sorry I am putting this up again. Still have had no luck in solving my
>problem.
>
>I have a custom tag in which I open the connection in the doStartTag()
>method and close the recordset etc in the doEndTag(). The code is at the
>end of the email.
>
>I know the connections are being pooled as I start mysql with logging.
>When I use the code below, the logs clearly show that a new connection
>is being made every time I access the page. However when I use the new
>version with the connection pooling specific stuff, the connections are
>made at first as necessary, and then reused for subsequent page hits(No
>new CONNECT log entries).
>
>The database and queries I used are identical, as I am running tomcat
>with 2 virtual hosts, dev and stage(dev is the new one and stage has the
>old code). The database both of them access is the same.
>
>I read somewhere that the jndi lookup may actually be slower than the
>mm.mysql driver creating a connection (The connection setup/teardown may
>not be that expensive in this case as the database is on the same
>dedicated network). But I am extremely skeptical of this thought, and I
>only came across that idea once, and it obviously flies in the face of
>everything else out there (I have a problem with long run on sentences).
>
>Any thoughts???
>
>Thanks
>
>Richie
>
>Here's the code ......
>
>    public int doStartTag() throws JspException
>    {
>       StringBuffer sql = new StringBuffer();
>         String path = "jdbc:mysql://jupiter/ajavaDB";
>
>...build sql string
>
>       try
>       {
>         //******THIS STUFF BELOW I REPLACE WITH THE CONNECTION POOL CODE
>       //   Class.forName("org.gjt.mm.mysql.Driver");
>       //   con = DriverManager.getConnection(path, "....", "....");
>
>          Context ctx = new InitialContext();
>          if(ctx != null)
>          {
>          DataSource ds =
>(DataSource)ctx.lookup("java:comp/env/jdbc/ajavaDB");
>                 if(ds != null)
>             {
>                 con = ds.getConnection();
>                 if(con != null)
>                 {
>                         stmt = con.createStatement();
>                         rs = stmt.executeQuery(sql.toString());
>                         setVariables();
>                 }//end if con
>             }//end if ds
>             }//end if ctx
>
>       } catch (SQLException e)
>       {
>          throw new JspTagException("An SQLException occurred!");
>       } catch (ClassNotFoundException e)
>       {
>          throw new JspTagException("JDBC Driver not found.");
>       }
>       return EVAL_BODY_TAG;
>    }
>
>
>    public int doEndTag() throws JspException
>    {
>       try
>       {
>          if(rs != null)
>          {
>             rs.close();
>             rs = null;
>          }
>          if(stmt != null)
>          {
>             stmt.close();
>             stmt = null;
>          }
>          if(con != null)
>          {
>             con.close();
>             con = null;
>          }
>       } catch (SQLException e)
>       {}
>
>       return EVAL_PAGE;
>    }
>
>Richie Chauhan
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org



LEGAL NOTICE

This electronic mail  transmission and any accompanying documents contain 
information belonging to the sender which may be confidential and legally 
privileged.  This information is intended only for the use of the 
individual or entity to whom this electronic mail transmission was sent as 
indicated above. If you are not the intended recipient, any disclosure, 
copying, distribution, or action taken in reliance on the contents of the 
information contained in this transmission is strictly prohibited.  If you 
have received this transmission in error, please delete the message.  Thank 
you  



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org