tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mariano" <mlo...@sescam.org>
Subject RE: NamingException
Date Wed, 02 Jan 2008 13:13:19 GMT
First of all if you are working with tomcat 5.5 you have to put your jdbc
library file in TOMCAT_HOME/common/lib but if you are using Tomcat 6.0 you
have to put files in TOMCAT_HOME/lib.

I think that ResourceParams is nested to Resource and you have it out of
Resource.

You must follow guidelines in
http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html
to create DBCP.

I hope this help you.

Mariano

-----Mensaje original-----
De: AbelMacAdam [mailto:abel.macadam@gmail.com]
Enviado el: miercoles, 02 de enero de 2008 14:05
Para: users@tomcat.apache.org
Asunto: NamingException



I have a piece of code that should get me a dataSource (from an example I'm
playing with from a Struts book):
[code]
    try {
      logger.info("DAOBase.getConnection: ====== InitialContext ======");
      context = new InitialContext();
      logger.info("DAOBase.getConnection: ====== context.lookup  ======");
      dataSource = (DataSource)
context.lookup("java:/comp/env/jdbc/myDataSource");
    }
    catch (NamingException e) {
      logger.info("DAOBase.getConnection: ====== NamingException ======",
e.fillInStackTrace());
      throw new DAOException();
    }
[/code]

This is a piece of my logging:
[logging]
13:04:33,449 INFO  app15a.action.CreateCustomerAction - AMc: ++++++
getConnection ++++++++
13:04:33,449 INFO  app15a.action.CreateCustomerAction -
DAOBase.getConnection: ====== InitialContext ======
13:04:33,449 INFO  app15a.action.CreateCustomerAction -
DAOBase.getConnection: ====== context.lookup  ======
13:04:33,449 INFO  app15a.action.CreateCustomerAction -
DAOBase.getConnection: ====== NamingException ======
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
	at app15a.dao.DAOBase.getConnection(DAOBase.java:34)
	at
app15a.dao.CustomerDAOMySQLImpl.createCustomer(CustomerDAOMySQLImpl.java:44)
	at app15a.action.CreateCustomerAction.execute(CreateCustomerAction.java:44)
	at
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProces
sor.java:421)
	at
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
	at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:290)
	at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:206)
	at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:233)
	at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va:175)
	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:263)
	at
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:
852)
	at
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(H
ttp11AprProtocol.java:584)
	at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1508)
	at java.lang.Thread.run(Unknown Source)
[/logging]

As you might have noticed, I'm fairly new to this part of the neighborhood.
What should I do to remove this error?

I was advised to put the JDBC driver in the common/lib directory of my
TOMCAT_HOME. I don't have a common directory. I do have a TOMCAT_HOME/lib
directory. Am I correct in assuming I put my driver in that directory?

I also added the following Context element to my
TOMCAT_HOME/conf/server.xml:
[code]
    <!-- AMc: 02/01/2008: MySQL DataSource Object -->
    <Context path="/app15a" docBase="app15a" reloadable="true" debug="8">
        <Loader checkInterval="7" reloadable="true" />
        <Resource name="jdbc/myDataSource" auth="Container"
type="javax.sql.DataSource" />
        <ResourceParams name="jdbc/myDataSource">
            <parameter>
                <name>factory</name>

<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
            </parameter>
            <parameter>
                <name>maxActive</name>
                <value>100</value>
            </parameter>
            <parameter>
                <name>maxWait</name>
                <value>10000</value>
            </parameter>
            <parameter>
                <name>username</name>
                <value>root</value>
            </parameter>
            <parameter>
                <name>password</name>
                <value></value>
            </parameter>
            <parameter>
                <name>driverClass</name>
                <value>com.mysql.jdbc.Driver</value>
            </parameter>
            <parameter>
                <name>url</name>
                <value>jdbc:mysql://localhost/test</value>
            </parameter>
        </ResourceParams>
    </Context>
  </Service>
</Server>
[/code]
Am I correct in assuming this piece of code does not contain a reference to
my JDBC driver?

Any help would be appreciated, as I do not see what else I can do.

TIA,
Abel
--
View this message in context:
http://www.nabble.com/NamingException-tp14578063p14578063.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message