🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: JNDI Connection Problem

#423
From: Tom
Date: Sat, 03 Dec 2005 22:57
159 lines
7253 bytes
Paul Furbacher [TeamB] wrote:
> Tom wrote:
> 
>> Steven - did you ever find a solution for this?  I'm having trouble 
>> getting a JNDI database resource set up within JBuilder 2006.  I can 
>> get it to work with Tomcat outside of Jbuilder, but not within 
>> JBuilder (due to fact that Jbuilder is managing the .xml/tomcat config 
>> - still trying to figure this out.)  Do you know where I can find a 
>> definitive set of instructions for configuring a JNDI database 
>> resource within Jbuilder 2006?
> 
> 
> I don't think this has changed from earlier versions.
> Currently, I have a rather large Web app that I'm
> maintaining using JBuilder 2006, and I have no
> problems with this.
> 
> The key issue is that you have to work with JBuilder's
> management of the server8080.xml file, and the context
> files.  There's plenty of good reading on editing these
> files in the newsgroup archives, and if you avail yourself
> to that resource, you'll save us a lot of typing.
> 
> Keywords:  "server8080" edit
> 
> Also look up datasource definition in the archives.
> 
> Finally, look at the context files in your project
> dir/Tomcat/conf.  Suppose I have a context called
> "commerce".  There'll be a "jb-commerce.xml" file
> there, initially only when you run your server
> (runtime configuration).  Do the editing thing
> described in the archives.  Do the adding of
> datasource definition as described in the
> archives.
> 
> It works.  Once you get it to work, you'll
> probably immediately grok why it works.
> I remembered being befuddled the first time
> I had to set this up.  But then, it was, how
> do they say it?  Intuitive.
> 
> Finally, this is actually a "servlets-jsp"
> or "enterprise" newsgroup topic because it's
> more a question about configuring the server
> and not about the database.  If you have
> further questions, post to either of those
> two newsgroups (but not both).
> 
> 
Thanks for input - still having trouble though:

I'm not seeing any context files in webapp/Tomcat/conf (other than the 
one the context.xml file I placed there as a troubleshooting step.)  Do 
I need to manually add the .xml file in this directory, or, use the same 
trick as editing the server8080.xml file (though as I mentioned I do not 
see any jb*.xml file there when the server is running.)

The MySQL library is set up correctly because I can access the database 
without JNDI.  Are there any other specific libraries (i.e., j2ee.jar, 
naming-common.jar, naming-factory-dbcp.jar, naming-factory.jar, 
naming-resources.jar, other?)

Here are my other files:


------user/jbproject/webapp/Tomcat/conf/server8080.xml ---

<?xml version="1.0" encoding="UTF-8"?>
<Server port="8081" shutdown="SHUTDOWN">
<Service name="Catalina">
<Connector acceptCount="10" connectionTimeout="60000" maxThreads="75" 
minSpareThreads="5" port="8080"/>
<Engine defaultHost="localhost" name="Catalina">
<Host appBase="C:\Documents and 
Settings\user\jbproject\webapp\Tomcat\webapps" autoDeploy="false" 
deployXML="false" name="localhost" unpackWARs="false">
<Context docBase="C:\Documents and 
Settings\user\jbproject\webapp\webmodule" path="/webmodule" 
reloadable="true"
workDir="C:\Documents and 
Settings\user\jbproject\webapp\Tomcat\work\webmodule">
<Resource name="jdbc/mysql" auth="Container" type="javax.sql.DataSource"
                maxActive="10" maxIdle="30" maxWait="10000"
                username="root" password="xxxx" 
driverClassName="com.mysql.jdbc.Driver"
                url="jdbc:mysql://localhost:3306/test"/>
</Context>
</Host>
</Engine>
</Service>
</Server>


------  .java code snippet -----------------
ctx = new InitialContext();
pool = (DataSource)ctx.lookup("java:comp/env/jdbc/mysql");

This is the code that is failing


---  user/jbproject/sidehire/webmodule/WEB-INF/web.xml ---------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
   <display-name>webmodule</display-name>
   <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>
   <servlet>
     <servlet-name>Faces Servlet</servlet-name>
     <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
   </servlet>
   <servlet-mapping>
     <servlet-name>Faces Servlet</servlet-name>
     <url-pattern>*.faces</url-pattern>
   </servlet-mapping>
   <servlet>
     <description>Added by JBuilder to compile JSPs with debug 
info</description>
     <servlet-name>debugjsp</servlet-name>
     <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
     <init-param>
       <param-name>classdebuginfo</param-name>
       <param-value>true</param-value>
     </init-param>
     <load-on-startup>3</load-on-startup>
   </servlet>
   <servlet-mapping>
     <servlet-name>debugjsp</servlet-name>
     <url-pattern>*.jsp</url-pattern>
   </servlet-mapping>
</web-app>


--------------------------------

Thanks for any help.  I did find this solution approach (see below) 
posted on the board - I tried to emulate this approach without success 
(note this solution did not seem to require use of any context.xml 
files - they only placed their resource information in the 
server8080.xml file.)

"SOLVED: Datasource in JBuilder 2005 (Configuring the Web Module)
... by putting the <Resource> in the server8080.xml and following the 
rest of theinformation in your inline post, I *FINALLY* am able to use a 
datasource from my ..."

Finally, I assume you were using Tomcat 5.5?  For this Tomcat version, 
Tomcat expects to read the JNDI context information from the 
/META-INF/context.xml file, not the server.xml file - so I assume 
Jbuilder is taking care of this behind the scenes.

thanks, Tom
Technical Details
Message-ID: <43922281$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!newshub.sdsu.edu!elnk-nf2-pas!elnk-pas-nf1!newsfeed.earthlink.net!pd7cy1no!shaw.ca!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <42c3a0a6$1@newsgroups.borland.com> <42c879ec$1@newsgroups.borland.com> <43913a32$1@newsgroups.borland.com> <43913ece$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1073da,2417608254d405db
X-Google-Attributes: gid1073da,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Sat, 03 Dec 2005 17:57:13 -0500
From: Tom <tom.butler@adephia.net>
User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.database
Subject: Re: JNDI Connection Problem
References: <42c3a0a6$1@newsgroups.borland.com> <42c879ec$1@newsgroups.borland.com> <43913a32$1@newsgroups.borland.com> <43913ece$1@newsgroups.borland.com>
In-Reply-To: <43913ece$1@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 68.235.63.81
Message-ID: <43922281$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1133650561 68.235.63.81 (3 Dec 2005 14:56:01 -0700)
Lines: 160
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!newshub.sdsu.edu!elnk-nf2-pas!elnk-pas-nf1!newsfeed.earthlink.net!pd7cy1no!shaw.ca!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail