Sorry, I didn't read your code thoroughly. Yeah, that context has nothing to do with your issue. What I could suggest is to test your jsp using 1.1-rc1 in a clean environment (like reboot your machine, startup tomcat manually). -----Original Message----- From: Jon Wilmoth [mailto:jonwilmoth@yahoo.com] Sent: October 16, 2003 11:22 AM To: Jakarta Commons Users List Subject: RE: [dbcp] Connection pooling error w/MySQL The difference is I'm doing a fully qualified JNDI path lookup for the DataSource from the root context and you're doing it relative to a sub context. I don't beleive this is causing the problem as I am getting a DataSource object (evident from the stacktrace). --- Phillip Qin wrote: > Mine is slightly different from yours. > > Context initContext = new InitialContext(); > Context jdbcContext = (Context) > initContext.lookup(_initContextName); > DataSource dataSource = > (DataSource) > jdbcContext.lookup(_jdbcContextName); > > -----Original Message----- > From: Jon Wilmoth [mailto:jonwilmoth@yahoo.com] > Sent: October 13, 2003 12:17 AM > To: Jakarta Commons Users List > Subject: Re: [dbcp] Connection pooling error w/MySQL > > Sorry about the delay. Here's everything you've > asked > for: > > There is a servlet that is loaded at application > startup that performs a db connection test. Calls > to > getConnection() on the DataSource after the webapp > has > been deployed also fail with the same error. Since > Tomcat doesn't support external jvm access to the > JNDI > implementation, I'm including the code for a struts > action used to test datasource health. > > HARDWARE - Compaq n600 > OS - Windows XP Professional SP1 > JAVA - HotSpot(TM) Server VM (build 1.4.2_01-b06, > mixed mode) > NUMBER_OF_PROCESSORS=1 > PROCESSOR_IDENTIFIER=x86 Family 6 Model 11 Stepping > 1, > GenuineIntel > NETWORK - N/A. Both tomcat & mysql server are on > same > machine in development env. > MYSQL - 4.0.15-NT using InnoDB > JDBC DRIVER - mysql-connector-java-3.0.8-stable > > type="javax.sql.DataSource"/> > > > > factory > > org.apache.commons.dbcp.BasicDataSourceFactory > > > username > mydbuser > > > password > mydbuserpassword > > > driverClassName > com.mysql.jdbc.Driver > > > url > jdbc:mysql://localhost:3306/testDB > > > removeAbandoned > true > > > removeAbandonedTimeout > 300 > > > logAbandoned > true > > > maxActive > 15 > > > maxIdle > 3 > > > maxWait > -1 > > > validationQuery > select sysdate from dual > > > defaultAutoCommit > false > > > > > Test Case Files: > ======================== > struts-config.xml > ======================== > > Foundation//DTD Struts Configuration 1.1//EN" > "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"> > > > type="org.apache.struts.action.DynaActionForm"> > type="java.lang.String" initial="jdbc/ChronosPool"/> > type="java.lang.String" initial="x_link"/> > > > > > type="com.apex.chronos.ui.system.TestDataSourceAction" > name="DataSourceTestForm" > scope="request" > input="system/healthCheck.jsp" > validate="false"> > path="/system/healthCheck.jsp"/> > path="/system/healthCheck.jsp"/> > > > > > ========================== > TestDataSourceAction.java > ========================== > package com.apex.chronos.ui.system; > > import java.sql.Connection; > import java.sql.PreparedStatement; > import java.util.ArrayList; > import javax.naming.InitialContext; > import javax.servlet.http.HttpServletRequest; > import javax.servlet.http.HttpServletResponse; > import javax.sql.DataSource; > import org.apache.struts.action.Action; > import org.apache.struts.action.ActionForm; > import org.apache.struts.action.ActionForward; > import org.apache.struts.action.ActionMapping; > import org.apache.struts.action.DynaActionForm; > > public class TestDataSourceAction extends Action { > > public static final String DATASOURCE_TEST_RESULTS > = > "dataSourceTestResults"; > public static final String JDBC_SUBCONTEXT_NAME = > "java:comp/env/jdbc"; > > public ActionForward execute(ActionMapping > mapping, ActionForm form, > > HttpServletRequest request, > HttpServletResponse response) { > DynaActionForm myForm = (DynaActionForm) form; > > > String dataSrc = (String) myForm.get("jndiName"); > String sql = (String) myForm.get("testSQL"); > > String dataSrcJndiPath = JDBC_SUBCONTEXT_NAME + > "/" > + dataSrc; > String result = "healthy"; > PreparedStatement ps = null; > Connection conn = null; > InitialContext ctx = null; > try { > ctx = new InitialContext(); > > //Lookup specified data source > DataSource ds = (DataSource) > ctx.lookup(dataSrcJndiPath); > > //run sql through to ensure healthy connection > conn = ds.getConnection(); > ps = conn.prepareStatement(sql); > boolean didExecute = ps.execute(); > if (!didExecute) { > result = "failed: No result set produced > from sql: > " + sql; > } > } catch (Exception e) { > result = "failed: " + e.getMessage(); > } finally { > if (ctx != null) { > try { > ctx.close(); > } catch (Exception e) {}//ignore > } > > if (ps != null) { > try { > ps.close(); > ps = null; > } catch (Exception e){}//ignore > } > if (conn != null) { > try { > conn.close(); > conn = null; > } catch (Exception e){}//ignore > } > } > > request.setAttribute(DATASOURCE_TEST_RESULTS, > result); > return mapping.findForward("success"); > } > } > > > ================= > healthCheck.jsp > ================= > <%@ page > language="java" > session="true" > isThreadSafe="false" > contentType="text/html" > isErrorPage="false" > %> > > <%@ page > import="com.apex.chronos.ui.system.TestDataSourceAction" > %> > <%@ page import="com.apex.common.SystemException" %> > <%@ page import="com.apex.common.jndi.TreeUtil" %> > <%@ page import="java.util.ArrayList" %> > <%@ page import="javax.naming.Context" %> > <%@ page import="javax.naming.InitialContext" %> > <%@ page import="javax.naming.NamingEnumeration" %> > <%@ page import="javax.sql.DataSource" %> > > <%@ taglib uri="struts-html.tld" prefix="html" %> > <%@ taglib uri="struts-bean.tld" prefix="bean" %> > <%@ taglib uri="struts-logic.tld" prefix="logic" %> > >

Test DataSources for connectivity health

> > focus="jndiName"> > > > > > > > > > > > > > >
DataSourceHealth Check Query
> > > size="60"/> ; >
> > > >
> > > >
>

>
> > > --- Dirk Verbeeck wrote: > > Let us first gather some more info. > > Hardware, OS, network (firewall, ...), versions of > > all relevant software > > Configuration of your database pool (server.xml) & > > database server (host > > access parameters) > > > > Is it during startup / under load? > > Can you provide a small test case? > > > > Can you retest using the latest versions of DBCP & > > pool (v1.1RC1)? > > http://cvs.apache.org/~dirkv/builds/ > > > > At the bottom of your stack trace you see that the > > cause is inside the > > driver > > > > ================ > > Caused > > by: java.sql.SQLException: Unable to connect to > any > > hosts due to exception: java.net.BindException: > > Address already in use: connect at > > > com.mysql.jdbc.Connection.createNewIO(Connection.java:1622) > > at > > > com.mysql.jdbc.Connection.(Connection.java:491) > > > > at > > > com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:346) > > at > > > org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConne > ctionFactory.java:83) > > ================ > > > > But let us investigate further... > > > > Dirk > > > > > > Jon Wilmoth wrote: > > > > >After doing some further research I think there's > > >might be a bug in Jakarata Common's DBCP. I was > > able > > >to successfully configure and test a connection > > pool > > >using the same MySQL Driver and connection > > parameters > > >with Weblogic 8.1 SP1. Should this move to the > > >developers list? Into Bugzilla? > > > > > > > > > > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: > > commons-user-unsubscribe@jakarta.apache.org > > For additional commands, e-mail: > > commons-user-help@jakarta.apache.org > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: > commons-user-unsubscribe@jakarta.apache.org > For additional commands, e-mail: > commons-user-help@jakarta.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org