tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shawn <javajun...@koyuru.com>
Subject Re: JNDI jdbc resources
Date Mon, 27 Jan 2003 03:08:53 GMT
What about server.xml?

  try{
> >                 Context ctx2 = new InitialContext();
> >                 out.print("Connecting1 : ");
> >                  Context envCtx2 = (Context)  
> > ctx2.lookup("java:/comp/env/");
> >                 out.print("Connecting2 : ");
> >              DataSource ds = (DataSource)  
> > envCtx2.lookup("jdbc/DBmultileague");
> >                 out.print("Connecting3 : ");
> > 
> >               if (ds != null) {
> >                         out.print("Query1 : ");
> >                 Connection conn = ds.getConnection();
> >                         out.print("Query2 : ");

That part worked for me too.  Is there an advantage to breaking your
Context into two pieces.  Anyway, I tried it like that with no problem.

Shawn


On Mon, 2003-01-27 at 09:21, Peng Tuck Kwok wrote:
> Let's have a look at your web.xml as well. Might be helpful.
> 
> Paul Carpenter wrote:
> > Hi All
> > 
> > I've scoured the list and got so close, yet so far from making the jdbc  
> > stuff work. With some help from Manav and other postings, this is what  
> > i see. can anyone solve the riddle?
> > 
> > Please see the cut'n'pastes below. I draw you attention to the fact  
> > that the connection looks good right up to the point where it's used -  
> > like the DataSource object is good (because "ds != null" is true), yet  
> > the getConnection method throws the often seen "Cannot load JDBC driver  
> > class 'null'" error.
> > 
> > I know this is very close.......what's missing?
> > 
> > I'm sure my jars are in the right place, as a regular forClass approach  
> > in the same webapp works with no problems?
> > 
> > 
> > Thanks
> > Paul
> > 
> > tomcat 4.1.12, Mac OSX 10.2.3
> > 
> > Output from my test servlet:
> > Simple lookup test :
> > dbName : org.apache.commons.dbcp.BasicDataSource@25debb
> > list() on /comp/env Context :
> > Binding : jdbc: org.apache.naming.NamingContext
> > listBindings() on /comp/env Context :
> > Binding : jdbc:  
> > org.apache.naming.NamingContext:org.apache.naming.NamingContext@41f80c
> > list() on full Context :
> > Binding : DBmultileague: org.apache.commons.dbcp.BasicDataSource
> > listBindings() on full Context today:
> > Binding : DBmultileague:  
> > org.apache.commons.dbcp.BasicDataSource:org.apache.commons.dbcp.BasicDat 
> > aSource@25debb
> > Connecting1 : Connecting2 : Connecting3 : Query1 :
> > 
> > The relevant servlet code;
> >         try {
> >             out.println("list() on full Context : ");
> >             NamingEnumeration enum2 = ctx.list("java:/comp/env/jdbc/");
> >             while (enum2.hasMoreElements()) {
> >                 out.print("Binding : ");
> >                 out.println(enum2.nextElement().toString());
> >             }
> >             out.println("listBindings() on full Context today: ");
> >             enum2 = ctx.listBindings("java:/comp/env/jdbc/");
> >             while (enum2.hasMoreElements()) {
> >                 out.print("Binding : ");
> >                 out.println(enum2.nextElement().toString());
> >             }
> >         } catch (NamingException e) {
> >             out.println("JNDI lookup failed : " + e);
> >         }
> >         try{
> >                 Context ctx2 = new InitialContext();
> >                 out.print("Connecting1 : ");
> >                  Context envCtx2 = (Context)  
> > ctx2.lookup("java:/comp/env/");
> >                 out.print("Connecting2 : ");
> >              DataSource ds = (DataSource)  
> > envCtx2.lookup("jdbc/DBmultileague");
> >                 out.print("Connecting3 : ");
> > 
> >               if (ds != null) {
> >                         out.print("Query1 : ");
> >                 Connection conn = ds.getConnection();
> >                         out.print("Query2 : ");
> > 
> > The context/resource definition:
> > <Context path="/DBmultileague-0.1-dev" docBase="DBmultileague-0.1-dev"  
> > debug="5" reloadable="true"  naming="true" crossContext="true">
> >        
> >     <Logger className="org.apache.catalina.logger.FileLogger"
> >             prefix="localhost_DBmultileague_log." suffix=".txt"  
> > timestamp="true"/>
> >                
> >     <Resource name="jdbc/DBmultileague" auth="Container"  
> > type="javax.sql.DataSource"/>
> >     
> >     <ResourceParams name="jdbc/DBmultileague">
> >         <Parameter><name>maxIdle</name><value>3000</value></Parameter>
> >         <Parameter><name>maxActive</name><value>10</value></Parameter>
> >         <Parameter><name>maxWait</name><value>10</value></Parameter>
> >         <Parameter><name>username</name><value>sa</value></Parameter>
> >         <Parameter><name>password</name><value></value></Parameter>
> >         <Parameter>
> >             <name>factory</name>
> >             <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
> >         </Parameter>
> >               <Parameter>
> >             <name>driverClassName</name>
> >             <value>com.sybase.jdbc2.jdbc.SybDriver</value>
> >         </Parameter>
> >         <Parameter>
> >             <name>url</name>
> >             <value>jdbc:sybase:Tds:PowerBookPaul:11222/multiLeague</value>
> >         </Parameter>
> >         <Parameter><name>initialPoolSize</name><value>2</value></Parameter>
> >     </ResourceParams>
> > 
> > 
> 
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>
-- 
shawn <javajunkie@koyuru.com>


--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message