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]



Reply via email to