I was making more test with this, I find that if I define the resource in a normal context it works, but I want to use defaultcontext to work with ant InstallTask, or is there another way to do this?

I attached my web.xml, this is the relevant entry in server.xml:

<DefaultContext debug="0" reloadable="true" crossContext="true">
  <Resource name="jdbc/ComercialDB"
               auth="Container"
               type="javax.sql.DataSource"/>

  <ResourceParams name="jdbc/ComercialDB">
    <parameter>
      <name>factory</name>
      <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    </parameter>

    <parameter>
      <name>maxActive</name>
      <value>100</value>
    </parameter>

    <parameter>
      <name>maxIdle</name>
      <value>30</value>
    </parameter>

    <parameter>
      <name>maxWait</name>
      <value>10000</value>
    </parameter>

    <parameter>
     <name>username</name>
     <value>***</value>
    </parameter>
    <parameter>
     <name>password</name>
     <value>***</value>
    </parameter>

    <parameter>
       <name>driverClassName</name>
       <value>org.gjt.mm.mysql.Driver</value>
    </parameter>

    <parameter>
      <name>url</name>

<value>jdbc:mysql://localhost:3306/comercial?autoReconnect=true</value>
    </parameter>
  </ResourceParams>

</DefaultContext>






Thanks for the help Colin.


_________________
Manolo Ramirez T.



Madere, Colin wrote:
Well then it may be something else.  I'm essentially doing what you are with
a JNDI datasource defined in the DefaultContext with nothing in the web.xml
(except to pass along the JNDI name so it's not hard-coded).  It breaks for
me (and a bunch of other people posting recently using 4.1.x) when I try to
move that to GlobalNamingResources and use a ResourceLink.

Post your server.xml and web.xml (or just relevant parts), maybe it's
something else.

-----Original Message-----
From: Manolo Ramirez T. [mailto:[EMAIL PROTECTED] Sent: Monday, August 25, 2003 3:50 PM
To: Tomcat Users List
Subject: Re: Can not load JNDI DataSource in Servlet.init()



No, I'm not using a ResourceLink.


_________________
Manolo Ramirez T.

Madere, Colin wrote:

So you are using a resource link in the DefaultContext either in server.xml or your web.xml?

-----Original Message-----
From: Manolo Ramirez T. [mailto:[EMAIL PROTECTED]
Sent: Monday, August 25, 2003 1:27 PM
To: Tomcat Users List
Subject: Re: Can not load JNDI DataSource in Servlet.init()


It's in DefaultContext, I checked the related messages, it seems like the same problem.

Thanks for the answer.

_________________
Manolo Ramirez T.

Madere, Colin wrote:


How is your JNDI resource configured?  In an explicitly defined
Context or in the DefaultContext?  ResourceLinked?

I ask because there are a number of folks with similar problems that
look to be something missing in how JNDI datasources are handled internally when using DefaultContext.


See other topics:

* ResourceLink and DefaultContext
* Tomcat 4.1 DefaultContext Bug?
* Question about Tomcat Documentation
* Globally defined JNDI DataSource

-----Original Message-----
From: Manolo Ramirez T. [mailto:[EMAIL PROTECTED]
Sent: Friday, August 22, 2003 10:55 PM
To: Tomcat Users List
Subject: Can not load JNDI DataSource in Servlet.init()


Hi all,


Why I can't load a JNDI resource on the init method of my servlet?
there
is no problem doing that in doGet() but on init() it doesn't work. the logs entry is:


java.sql.SQLException: Cannot load JDBC driver class 'null'

It's the same code! What I'm missing?

this is my servlet code:






package libreria;


import java.io.PrintWriter;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;


public class MyServlet extends HttpServlet {


   public void init (ServletConfig config) throws ServletException{
        super.init(config);
        try {
            Context ctx = new InitialContext();
            if(ctx==null) {
                System.out.println("fallo InitialContext");
                return;
            }

DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/ComercialDB");
if(ds==null) {
System.out.println("fallo lookup");
return;
}


Connection conn = ds.getConnection();

            Statement stm = conn.createStatement();
        
            ResultSet rs = stm.executeQuery("select * from pruebas");

while(rs.next()) {
System.out.println(rs.getInt("id")+"::"+rs.getString("nombre")+"::"+rs
.getSt
ring("apellido"));
}
}
catch(Exception e) {
e.printStackTrace();
}
}


   public void doGet(HttpServletRequest request, HttpServletResponse
response) throws IOException,ServletException {
        response.setContentType("text/plain");
        PrintWriter out= response.getWriter();
        out.println("holas muchas");

        try {
            Context ctx = new InitialContext();
            if(ctx==null) {
                out.println("fallo InitialContext");
                return;
            }

DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/ComercialDB");
if(ds==null) {
out.println("fallo lookup");
return;
}


Connection conn = ds.getConnection();

            Statement stm = conn.createStatement();
        
            ResultSet rs = stm.executeQuery("select * from pruebas");

while(rs.next()) {
out.println(rs.getInt("id")+"::"+rs.getString("nombre")+rs.getString("
apelli
do"));
}
}
catch(Exception e) {
e.printStackTrace(out);
}
}
}






Regards.

_____________
Manolo Ramirez T.


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd";>

<web-app>

    <display-name>Aplicacion Web de Libreria</display-name>

    <description>Esta aplicacion matiene una base de datos de libros.</description>
<!--
    <listener>
        <listener-class>libreria.ContextListener</listener-class>
    </listener>
-->
    <servlet>
        <servlet-name>PruebasJava</servlet-name>
        <servlet-class>libreria.MyServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>PruebasJava</servlet-name>
        <url-pattern>/pruebas</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>Index.jsp</welcome-file>
    </welcome-file-list>

    <resource-ref>
        <description>DB Connection</description>
        <res-ref-name>jdbc/ComercialDB</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>


</web-app>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to