The method of defining JNDI resources in tomcat changed from 5.0 to 5.5. The book appears to be describing the method for 5.5. See http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html for details related to tomcat 5.5.

The java code used in jsps and servlets to access the data source is still the same. That part can come from the book.

--David

Kevin Hart wrote:
The attachments in my previous message got mangled. Sorry, I'm a newbie. Here is the relevant portion of the server.xml file (the formatting in this
will probably get mangled too):

..
<DefaultContext>
<Resource name="jdbc/WroxTC5" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/WroxTC5">
<parameter><name>driverClassName</name><value>com.mysql.jdbc.Driver</value></parameter>
 
<parameter><name>url</name><value>jdbc:mysql://localhost/wroxtomcat</value></parameter>
<parameter><name>username</name><value>*****</value></parameter>
<parameter><name>password</name><value>*****</value></parameter>
<parameter><name>maxActive</name><value>20</value></parameter>
<parameter><name>maxIdle</name><value>30000</value></parameter>
<parameter><name>maxWait</name><value>100</value></parameter> <parameter><name>factory</name><value>org.apache.commons.dbcp.BasicDataSourceFactory</value></parameter>
</ResourceParams>
</DefaultContext>

      </Host>
    </Engine>
  </Service>
</Server>

And here is the relevant portion of the web.xml file:

..
<resource-ref>
   <res-ref-name>jdbc/WroxTC5</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
   <res-auth>Container</res-auth>
</resource-ref>
</web-app>

The code in the jsp that generates the exception is line 14 of the following
snippet:

..
11: <%
12: InitialContext initCtx = new InitialContext();
13: if( initCtx != null ) {
14:    DataSource ds = (DataSource)
initCtx.lookup("java:comp/env/jdbc/WroxTC5");
15:    Connection conn = ds.getConnection();
16:    Statement stmt = conn.createStatement();
17:    ResultSet rset = stmt.executeQuery("select * from employee;");
..

As you can see, I'm just trying to get an example working.

Thanks again for any help,
Kevin

Quoting Kevin Hart <[EMAIL PROTECTED]>:

Hello,

I'm trying to get a jsp to access a mysql database.  I'm using the
"preferred" JNDI resources approach with Tomcat, but I keep getting the
NamingException: Cannot create resource instance error.  I know others
have posted with this error.  I've read some of those posts, but
the solutions don't seem to fix the problem in my case.

I'm using FC5, MySql 5.0.22 and Apache Tomcat 5.5.15.  I attach the
following files:

exception.report is a copy of the html page showing the error.

common.lib.contents is the output of a script session to show the
contents of my /usr/share/tomcat5/common/lib directory.  I have at least
the
following in there: mysql-connector-java-5.0.3-bin.jar, commons-pool.jar,
common-collections.jar, naming-factory.jar and naming-resources.jar.

server.xml is my /usr/share/tomcat5/conf/server.xml file.  I have a
<Resource> tag inside a <DefaultContext> tag inside the <host> element
(see the end of the file).

web.xml is from the jsp-examples/WEB-INF directory.  (I'm just tacking
my jdbctest.jsp onto the existing jsp-examples webapp.)  The
<resource-ref> tag is at the end of that file.

Having no experience with Tomcat, I'm basically following instructions
from Wrox's book "Professional Apache Tomcat 5."  I must be misreading
it.

Thanks in advance,
Kevin





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



--
David Smith
Network Operations Supervisor
Department of Entomology
Cornell University
2132 Comstock Hall
Ithaca, NY 14853
Phone: (607) 255-9571
Fax: (607) 255-0940


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

Reply via email to