🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.database
Article #429

Re: Help with JNDI Datasource in JBuilder 2006

#429
From: Paul Furbacher [TeamB]
Date: Wed, 07 Dec 2005 08:02
116 lines
5181 bytes
Tom wrote:

> Paul - thanks for all of your help and responses.

Well, I'm learning things as we go along.  Today
I just migrated a large Web app from Tomcat 4.1.x
to Tomcat 5.5.12 and it took time and didn't go smoothly.
One thing which caught me off-guard was the change
from using <ResourceParameters> to <Resource> attributes.
Anyway, back to the matter at hand.

> I think I have the server8080.xml file set up correctly and took your
> advice to move the project to a directory structure that does not
> contain embedded spaces.
> 
> You mention "I placed the resource def
> in <Context> element in the server8080.xml, and referenced
> it from the Spring app context xml file."

Yes, this was just to prove that the resource (the datasource)
was being instantiated correctly.  But configuring for Spring
is different from that of a non-Spring Web app.

> This may be the piece I am missing.  Does this only apply to Spring 
> applications (app context file)?  I am using JSF (not Spring)and am 
> placing the reference within the application web.xml file?  Is this 
> correct?

As you pointed out in your first message in this thread,
you initially put the <res-ref> definition in the web.xml
file where it should be.  Quoting you:

> 2.  Declare your Resource Requirements
>   *  following code included in web.xml within project:
>    /myapp/webmodule/WEB-INF/web.xml
>
>   <resource-ref>
>     <description>MySQL DB Connection</description>
>     <res-ref-name>jdbc/mysql</res-ref-name>
>     <res-type>javax.sql.DataSource</res-type>
>     <res-auth>Container</res-auth>
>   </resource-ref>

I went back to the Bookstore JSF example Web app and did the
following:

1. The server is already set to Tomcat 5.5.

2. In the server8080.xml, I did the following:

  - removed the comment line
  - expanded the <Context .../> to read
     <Context ...>
     </Context>
  - nested in the <Context></Context>
    the dataSource <Resource> definition
    (I'll use the one from your first post here,
     I've broken lines for readability only)

        <Context  debug="6"
           docBase=
            "d:\<path_to_samples>\samples\jsf\Tomcat\Tomcat\bookstore"
          path="/bookstore"
          reloadable="true"
          workDir="... just lazy to type it ... >

         <Resource name="jdbc/mysql"
            auth="Container"
            type="javax.sql.DataSource"
            maxActive="10" maxIdle="30" maxWait="10000"
            username="root" password="pat"
            driverClassName="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost:3306/test" />
        </Context>


3. In the class DBAccess.java, I modified the constructor:

   public DbAccess() {
     currentUser = null;

     // PF added this to test getting dataSource from JNDI
     try {
       InitialContext ctx = new InitialContext();
       DataSource ds =
           (DataSource)ctx.lookup("java:comp/env/jdbc/mysql");
     }
     catch ( Exception ex ) {
       ex.printStackTrace();
     }
   }

I don't do anything with the dataSource, but the fact that the
Web app starts up successfully and no stacktraces are shown in
the Message Pane shows that this way of configuring a JNDI
dataSource works for Tomcat 5.5.9 being managed by JBuilder
2006.  However, from my experience today with a stand-alone
Tomcat 5.5.12, this way of configuring in server.xml is
frowned upon, and should be done in a META-INF/context.xml
file, as you noted earlier in the discussion.


-- 


Paul Furbacher (TeamB)

   Save time, search the archives:
        http://info.borland.com/newsgroups/ngsearch.html

   Is it in Joi Ellis's Faq-O-Matic?
        http://www.visi.com/~gyles19/fom-serve/cache/1.html

   Finally, please send responses to the newsgroup only.
   That means, do not send email directly to me.
   Thank you.
Technical Details
Message-ID: <439696f1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <438a4e03$1@newsgroups.borland.com> <438be2d7$1@newsgroups.borland.com> <43939b56$1@newsgroups.borland.com> <4394a216$1@newsgroups.borland.com> <439662f1$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1073da,634e789a0dc75d45
X-Google-Attributes: gid1073da,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Wed, 07 Dec 2005 03:02:52 -0500
From: "Paul Furbacher [TeamB]" <pfurbacher@mac.com>
Organization: Reverse Alchemy, Inc.
User-Agent: Mozilla Thunderbird 1.0.6 (Macintosh/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.database
Subject: Re: Help with JNDI Datasource in JBuilder 2006
References: <438a4e03$1@newsgroups.borland.com> <438be2d7$1@newsgroups.borland.com> <43939b56$1@newsgroups.borland.com> <4394a216$1@newsgroups.borland.com> <439662f1$1@newsgroups.borland.com>
In-Reply-To: <439662f1$1@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 69.142.194.228
Message-ID: <439696f1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1133942513 69.142.194.228 (7 Dec 2005 00:01:53 -0700)
Lines: 116
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail