javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
Anyway, I found how to configure the application context with ant (I think that it was not posible), so I can live without DefaultContext.
Thanks for the help.
Regards,
_________________ Manolo Ramirez T.
Madere, Colin wrote:
Ok, you are using a resource-ref. But I'm not sure why since you have the resource defined in the DefaultContext. Try removing the resource-ref from your web.xml and see if you get a different error.
(BTW: Better not to use attachments since this list is archived and not all attachments work for all mail readers, etc).
-----Original Message-----
From: Manolo Ramirez T. [mailto:[EMAIL PROTECTED] Sent: Monday, August 25, 2003 7:01 PM
To: Tomcat Users List
Subject: Re: Can not load JNDI DataSource in Servlet.init()
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")+"::"+r
s
.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]
--------------------------------------------------------------------- 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]
