tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John McAuley" <>
Subject JNDI lookup connection datasource microsoft sql server
Date Mon, 10 Jun 2002 09:17:17 GMT
Hi folks,

    I am trying to use Microsoft's jdbc driver for ms sql with Tomcat and am running into
trouble with the JNDI lookup method.  I look for a datasource and get null.  If I use the
class.forname method the driver is found and works perfectly but I am unable to get it working
with the JNDI look up,  This is very frustrating and seems to crop up a couple of times with
fellow users.  Any thoughts ??

Help much appreciated.



 <Context path="/tools" docBase="tools" debug="0" reloadable="true">
                <Resource name="jdbc/ToolsDB" auth="Container"
                <ResourceParams name="jdbc/ToolsDB">


                  Resource reference to a factory for java.sql.Connection
                 instances that may be used for talking to a particular
                 database that is configured in the server.xml file.

Code Snippet

  Context ctx = new InitialContext();
                 Context envCtx = (Context)ctx.lookup("java:comp/env");
                 out.println("Got first context.");

                NamingEnumeration enum =ctx.listBindings("java:comp/env/jdbc");
                  while( enum.hasMore() ) {
                   out.println("Binding: " + ((Binding) + "<br>");
                    DataSource ds = (DataSource)envCtx.lookup("jdbc/ToolsDB");
                    out.println("Got the second context." + "<br>" + "<br>");

                  if (ds != null)
                         out.println("Getting the connection from the context.");
                         Connection connection = ds.getConnection();
                                        out.println("not working");

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message