/WEB-INF/web.xml: <resource-ref> <res-ref-name>jdbc/jpetstore</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
--looks for jdbc/jpetstore and finds it here in dataAccess-context.xml-- WEB-INF/dataAccess-context.xml <!-- Main JNDI DataSource for J2EE environments --> <!-- Refers to the main database, containing product and account data --> <!-- (see dataAccessContext-local.xml for an alternative) --> <jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/jpetstore"/> --looks for dataSource and finds it here in dataAccessContext-local -- WEB-INF/dataAccessContext-local.xml <!-- Local Apache Commons DBCP DataSource that refers to a combined database --> <!-- (see dataAccessContext-jta.xml for an alternative) --> <!-- The placeholders are resolved from jdbc.properties through --> <!-- the PropertyPlaceholderConfigurer in applicationContext.xml --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> </bean> HTH Martin ______________________________________________ Verzicht und Vertraulichkeitanmerkung / Note de déni et de confidentialité Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen. Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni. > Date: Mon, 6 Apr 2009 17:30:55 +0100 > From: p...@pidster.com > To: users@tomcat.apache.org > Subject: Re: javax.naming.NamingException: Cannot create resource instance > > Mighty Tornado wrote: > > JVM: 1.5.0_16Tomcat: 6.0.16 2 > > OS: Mac OS X Leopard > > > > Hi, > > > > I defined the following context.xml under META-INF: > > > > <?xml version="1.0" encoding="UTF-8"?> > > > > <Context path="/Household" docBase="Household" debug="5" reloadable="true" > > crossContext="true"> > > > > <Resource > > > > auth="Container" > > > > description="DB Connection" > > > > name="jdbc/vhousehold" > > > > type="javax.sql.DataSource" > > > > password="vhousehold" > > > > driverClassName="com.mysql.jdbc.Driver" > > > > maxIdle="2" > > > > maxWait="5000" > > > > validationQuery="/* PING */ SELECT 1;" > > > > username="vhousehold" > > > > url="jdbc:mysql://localhost:3306/vhousehold" > > > > maxActive="4"/> > > > > </Context> > > > > > > In web.xml I have the following: > > > > > > <resource-ref> > > > > <description>Connection Pool</description> > > > > <res-ref-name>jdbc/vhousehold</res-ref-name> > > > > <res-type>javax.sql.Datasource</res-type> > > > > <res-auth>Container</res-auth> > > > > </resource-ref> > > > > > > I try to get this data source in my application using the following code: > > > > > > DataSource ds = (DataSource)initContext.lookup( > > "java:/comp/env/jdbc/vhousehold"); > > > > > > and it fails. This is the exception I get: > > > > javax.naming.NamingException: Cannot create resource instance > > > > at > > org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:143) > > > > at > > javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304) > > > > at org.apache.naming.NamingContext.lookup(NamingContext.java:793) > > > > at org.apache.naming.NamingContext.lookup(NamingContext.java:140) > > > > at org.apache.naming.NamingContext.lookup(NamingContext.java:781) > > > > at org.apache.naming.NamingContext.lookup(NamingContext.java:140) > > > > at org.apache.naming.NamingContext.lookup(NamingContext.java:781) > > > > at org.apache.naming.NamingContext.lookup(NamingContext.java:153) > > > > at > > org.apache.naming.SelectorContext.lookup(SelectorContext.java:137) > > > > at javax.naming.InitialContext.lookup(InitialContext.java:351) > > > > at > > com.vhousehold.dao.RandomPhraseDAO.getPhrases(RandomPhraseDAO.java:60) > > > > at > > com.vhousehold.model.RandomPhraseModel.getRandomPhrase(RandomPhraseModel.java:19) > > > > at com.vhousehold.servlet.VHController.doPost(VHController.java:52) > > > > at com.vhousehold.servlet.VHController.doGet(VHController.java:35) > > > > at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) > > > > at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) > > > > at > > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) > > > > at > > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) > > > > at > > org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) > > > > at > > org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) > > > > at > > org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) > > > > at > > org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) > > > > at > > org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) > > > > at > > org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) > > > > at > > org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845) > > > > at > > org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) > > > > at > > org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) > > > > at java.lang.Thread.run(Thread.java:613) > > > > > > Any suggestions as to what I am doing wrong? > > You've added the path and docBase attributes to your > META-INF/context.xml. Don't do that. > > Are the credentials you're using for the database correct? > > p > > > > Thanks. > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org > _________________________________________________________________ Windows Live™: Keep your life in sync. http://windowslive.com/explore?ocid=TXT_TAGLM_WL_allup_1a_explore_042009