Don�t use it in init( ) method, only doPost( ) or doGet( ).

> ----------
> De:   Burgess, Jay S[SMTP:[EMAIL PROTECTED]
> Responder:    Tomcat Users List
> Enviada:      quarta-feira, 28 de janeiro de 2004 12:35
> Para:         [EMAIL PROTECTED]
> Assunto:      JDBC/DBCP problems
> 
> I'm obviously missing something important with regards to moving our
> database/JDBC connectivity to use JNDI DataSource/DBCP.  I've read and
> re-read the docs, looked at every related message in the archive, and
> Google'd every set of keywords I can think of, but still no luck.
> Here's the issue:
> 
> Tomcat version is 4.1.29 on Windows XP.  I'm attempting to connect to
> SQL Server.  The JDBC driver JARs are in CATALINA_HOME\common\lib, and
> since everything works fine if I manually load the driver via
> Class.forName(), I don't think my problem is related to my driver files
> location.  When attempting to use getConnection(), however, I get the
> dreaded "Cannot create JDBC driver of class '' for connect URL 'null',
> cause: No suitable driver" error.  The highlights of my configuration
> are below.
> 
> -------------------------
> SERVER.XML
> -------------------------
> <GlobalNamingResources>
> <Resource name="jdbc/mydb" auth="Container" type="javax.sql.DataSource"
> description="The database." />
>     <ResourceParams name="jdbc/mydb">
>     <parameter>
>         <name>factory</name>
>         <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
>     </parameter>
>     <parameter>
>         <name>url</name>
> <value>jdbc:microsoft:sqlserver://###.###.###.###:1433;Database=MyDB</va
> lue>
>     </parameter>
>     <parameter>
>         <name>driverClassName</name>
>         <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
>     </parameter>
>     <parameter>
>         <name>username</name>
>         <value>MyUsername</value>
>     </parameter>
>     <parameter>
>         <name>password</name>
>         <value>MyPassword</value>
>     </parameter>
> ...
> </GlobalNamingResources>
> 
> -------------------------
> WEB.XML
> -------------------------
> <resource-ref>
>     <description>Some description. </description>
>     <res-ref-name>jdbc/mydb</res-ref-name>
>     <res-type>javax.sql.DataSource</res-type>
>     <res-auth>Container</res-auth>
> </resource-ref>
> 
> -------------------------
> In my servlet's init():
> -------------------------        
> Context initialContext = new InitialContext();
> Context envContext = (Context) initialContext.lookup("java:comp/env");
> DataSource dataSource = (DataSource) envContext.lookup("jdbc/mydb");
> Connection conn = dataSource.getConnection(); // throws exception
> 
> -------------------------
> Further info:
> -------------------------        
> Adding the following line after acquiring dataSource above, I get "class
> 
> org.apache.commons.dbcp.BasicDataSource":
> 
>     System.out.println(dataSource.getClass());
> 
> And if I add the following, I get
> "[EMAIL PROTECTED]":
> 
>     System.out.println((org.apache.commons.dbcp.BasicDataSource)
> dataSource);
> 
> So, since it looks like a valid BasicDataSource object, I tried the
> following, but get "null" back:
> 
>     System.out.println(((org.apache.commons.dbcp.BasicDataSource)
> dataSource).getUrl());
> 
> This seems to indicate that the object isn't initialized?
> 
> Turning on debug for the relevant listeners (NamingContextListener and
> GlobalResourcesLifecycleListener), I see the following related info in
> my Tomcat console window, which looks good from what I understand:
> 
> Jan 28, 2004 9:06:11 AM org.apache.coyote.http11.Http11Protocol init
> INFO: Initializing Coyote HTTP/1.1 on port 8080
> NamingContextListener[/]: Creating JNDI naming context
> NamingContextListener[/]: Resource parameters for mydb =
> ResourceParams[name=mydb, parameters=
> {url=jdbc:microsoft:sqlserver://###.###.###.###:1433;Database=MyDB,
> maxIdle=4,
> maxActive=8, 
> driverClassName=com.microsoft.jdbc.sqlserver.SQLServerDriver, 
> maxWait=10000, 
> removeAbandoned=true, 
> username=MyUsername, 
> factory=org.apache.commons.dbcp.BasicDataSourceFactory, 
> logAbandoned=true, 
> removeAbandonedTimeout=60, 
> password=MyPassword}]
> NamingContextListener[/]: Adding resource ref mydb
> NamingContextListener[/]: ResourceRef[
> className=javax.sql.DataSource,
> factoryClassLocation=null,
> factoryClassName=org.apache.naming.factory.ResourceFactory,
> {type=description,content=The database.},
> {type=scope,content=Shareable},
> {type=auth,content=Container},
> {type=url,content=
> jdbc:microsoft:sqlserver://###.###.###.###:1433;Database=MyDB},
> {type=maxIdle,content=4},
> {type=maxActive,content=8},
> {type=driverClassName,content=com.microsoft.jdbc.sqlserver.SQLServerDriv
> er},{type=maxWait,content=10000},
> {type=removeAbandoned,content=true},
> {type=username,content=MyUsername},
> {type=factory,content=org.apache.commons.dbcp.BasicDataSourceFactory},
> {type=logAbandoned,content=true},
> {type=removeAbandonedTimeout,content=60},
> {type=password,content=MyPassword}]
> GlobalResourcesLifecycleListener: Creating MBeans for Global JNDI
> Resources in Context '' [EMAIL PROTECTED]
> GlobalResourcesLifecycleListener: Processing resource mydb
> java.lang.String
> Starting service Tomcat-Standalone
> Apache Tomcat/4.1.29
> 
> Any help would be much appreciated.
> 
> Jay
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

Reply via email to