🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.database
11 messages
11 total messages Started by Tom Butler Mon, 28 Nov 2005 00:24
Help with JNDI Datasource in JBuilder 2006
#412
Author: Tom Butler
Date: Mon, 28 Nov 2005 00:24
95 lines
4786 bytes
Need help getting JNDI MySQL database source setup correctly within JBuilder
2006 to support a JSF application.   I am able to access the database using
a non-JNDI based approach, and, I was also able to get JNDI to work outside
of JBuilder 2006 using the configuration described below.

I am using the following tomcat documentation as a guide:
http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto.html

I have looked through a number of posts and examples, but at this point
(after many non-frutile hours) need someone with experience to help me to
get the configuration correct.

1.  Install JDBC Driver
    *  have 'mysql-connector-java-3.1.11-bin.jar' installed to
/myapp/webmodule/WEB-INF/lib
    * also have JDBC driver installed to
/JBuilder2006/thirdparty/jakarta-tomcat-5.5.9/common/lib (this was done as a
troubleshooting step though; prefer to only install this within the project
directory)

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>

3.  Code your Application's Use of this Resource
   *  project code from source.java file (note: try/catch blocks not
included)

           DataSource pool = null;
           Connection conn = null;
           PreparedStatement stmt = null;
           ResultSet rs = null;
           String sql = "select * from categories";

            ctx = new InitialContext();
            pool = (DataSource)ctx.lookup("java:comp/env/jdbc/mysql");
           conn = pool.getConnection();
            stmt = conn.prepareStatement(sql);
            rs = stmt.executeQuery();  (NOTE! this is statement that causes
the error)

4. Configure Tomcat's Resource Factory
   * context.xml contents located at:
/JBuilder2006/thirdparty/jakarta-tomcat-5.5.9/conf/context.xml

       <Context  debug="5" reloadable="true" crossContext="true">
       <WatchedResource>WEB-INF/web.xml</WatchedResource>
      <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>

    note: I also tried to add this same data to a context.xml file located
at /myapp/webmodule/META-INF/context.xml;  however, I could not get this
configuration to work, so I placed the context.xml back under the
jakarta-tomcat-5.5.9/conf folder.


ERRORS RECEIVED:
Receive an exception when try to execute the 'rs.=stmt.executeQuery()'
statement.  Following is initial start of stack trace:

Nov 27, 2005 7:10:29 PM com.sun.faces.lifecycle.InvokeApplicationPhase
execute
SEVERE: #{bn_searchproviders.search}: javax.faces.el.EvaluationException:
java.sql.SQLException
javax.faces.FacesException: #{bn_searchproviders.search}:
javax.faces.el.EvaluationException: java.sql.SQLException
 at
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImp
l.java:78)

ALSO TRIED:
* Used Enterprise | Enterprise Setup to add mysql.config to point to mysql
jdbc driver (not sure if I needed this, but tried it as a troubleshooting
step.)
* If I do not attempt to do a JNDI lookup, and just load the database driver
directly (using  Class.forName("com.mysql.jdbc.Driver")), everything works
fine (but I don't have the DBCP pooling capability.)
*  Was able to get a similar configuration setup to work outside of the
JBuilder 2006 IDE environment

ANY SUGGESTIONS?
* Do I need anything specified in the server.xml file?

THANKS FOR ANY HELP!
Re: Help with JNDI Datasource in JBuilder 2006
#413
Author: Paul Furbacher [TeamB]
Date: Tue, 29 Nov 2005 05:11
91 lines
4656 bytes
Tom Butler wrote:

> Need help getting JNDI MySQL database source setup correctly within JBuilder
> 2006 to support a JSF application.   I am able to access the database using
> a non-JNDI based approach, and, I was also able to get JNDI to work outside
> of JBuilder 2006 using the configuration described below.
> 
> I am using the following tomcat documentation as a guide:
> http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto.html
> 
> I have looked through a number of posts and examples, but at this point
> (after many non-frutile hours) need someone with experience to help me to
> get the configuration correct.
> 
> 1.  Install JDBC Driver
>     *  have 'mysql-connector-java-3.1.11-bin.jar' installed to
> /myapp/webmodule/WEB-INF/lib

No, you don't manage this; JBuilder does.  As noted five
gazillion times in these newsgroups, you create a JBuilder
library (see JBuilder Help if you don't know how to do this)
and add it to your project.  You configure your Web Module to
copy all resources.  Read the JBuilder Help on developing
Web apps and all about Web Module configuration. Note the
Content > Dependencies page in the Web Module properties
dialog.  (By default, your "required libraries" are set to
"Include all" which is what you want.)  Use the samples/jsf/
Tomcat/bookstore.jpx Web module as a learning tool.

>     * also have JDBC driver installed to
> /JBuilder2006/thirdparty/jakarta-tomcat-5.5.9/common/lib (this was done as a
> troubleshooting step though; prefer to only install this within the project
> directory)

No, don't put the driver lib in the thirdparty dirs.

> 
> 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>

This is correct.

> [...]
> 4. Configure Tomcat's Resource Factory
>    * context.xml contents located at:
> /JBuilder2006/thirdparty/jakarta-tomcat-5.5.9/conf/context.xml
 > [...]

JBuilder manages Tomcat runs, so I doubt that monkeying
with the thirdparty directory XML files will get you where
you want to go.  In general, don't touch those.

> [...] 
> ANY SUGGESTIONS?
> * Do I need anything specified in the server.xml file?

Yes, isn't that the place where you generally place the
resource definition?  I just opened up the JBuilder/samples/
jsf/Tomcat/bookstore.jpx and tested using Tomcat 5.5.  Do
this yourself, and run the "Server" runtime config.  Then
while the Web app is running, do a "File open" in JBuilder,
navigate to the "Project" dir via the "Favorites" panel
on the left.  Click on the "Tomcat/conf" dir, and open
the server8080.xml file.  From here on in, I'll ask you
to do some research: following the generously available
instructions in the newsgroup archives on editing "server8080.xml" 
(search keywords "edit server8080 tomcat"), edit the file, adding
your <Resource ...> definition.


-- 


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.
Re: Help with JNDI Datasource in JBuilder 2006
#424
Author: Tom
Date: Mon, 05 Dec 2005 01:45
116 lines
5956 bytes
Paul Furbacher [TeamB] wrote:
> Tom Butler wrote:
> 
>> Need help getting JNDI MySQL database source setup correctly within 
>> JBuilder
>> 2006 to support a JSF application.   I am able to access the database 
>> using
>> a non-JNDI based approach, and, I was also able to get JNDI to work 
>> outside
>> of JBuilder 2006 using the configuration described below.
>>
>> I am using the following tomcat documentation as a guide:
>> http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto.html
>>
>> I have looked through a number of posts and examples, but at this point
>> (after many non-frutile hours) need someone with experience to help me to
>> get the configuration correct.
>>
>> 1.  Install JDBC Driver
>>     *  have 'mysql-connector-java-3.1.11-bin.jar' installed to
>> /myapp/webmodule/WEB-INF/lib
> 
> 
> No, you don't manage this; JBuilder does.  As noted five
> gazillion times in these newsgroups, you create a JBuilder
> library (see JBuilder Help if you don't know how to do this)
> and add it to your project.  You configure your Web Module to
> copy all resources.  Read the JBuilder Help on developing
> Web apps and all about Web Module configuration. Note the
> Content > Dependencies page in the Web Module properties
> dialog.  (By default, your "required libraries" are set to
> "Include all" which is what you want.)  Use the samples/jsf/
> Tomcat/bookstore.jpx Web module as a learning tool.
> 
>>     * also have JDBC driver installed to
>> /JBuilder2006/thirdparty/jakarta-tomcat-5.5.9/common/lib (this was 
>> done as a
>> troubleshooting step though; prefer to only install this within the 
>> project
>> directory)
> 
> 
> No, don't put the driver lib in the thirdparty dirs.
> 
>>
>> 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>
> 
> 
> This is correct.
> 
>> [...]
>> 4. Configure Tomcat's Resource Factory
>>    * context.xml contents located at:
>> /JBuilder2006/thirdparty/jakarta-tomcat-5.5.9/conf/context.xml
> 
>  > [...]
> 
> JBuilder manages Tomcat runs, so I doubt that monkeying
> with the thirdparty directory XML files will get you where
> you want to go.  In general, don't touch those.
> 
>> [...] ANY SUGGESTIONS?
>> * Do I need anything specified in the server.xml file?
> 
> 
> Yes, isn't that the place where you generally place the
> resource definition?  I just opened up the JBuilder/samples/
> jsf/Tomcat/bookstore.jpx and tested using Tomcat 5.5.  Do
> this yourself, and run the "Server" runtime config.  Then
> while the Web app is running, do a "File open" in JBuilder,
> navigate to the "Project" dir via the "Favorites" panel
> on the left.  Click on the "Tomcat/conf" dir, and open
> the server8080.xml file.  From here on in, I'll ask you
> to do some research: following the generously available
> instructions in the newsgroup archives on editing "server8080.xml" 
> (search keywords "edit server8080 tomcat"), edit the file, adding
> your <Resource ...> definition.
> 
> 
No luck still - note I'm working on this issue now as a separate thread 
'JNDI Connection Problem Thread' (in this newsgroup), however, I wanted 
to mention that I took a look at the Bookstore code and saw that it does 
not use JNDI / Connection Pooling:

from bookstore dbaccess.java
  Class.forName(driverClassName);
  Connection con = DriverManager.getConnection(url, user, password);

So this is not a good representative example.  I think one reason why 
others have stumbled on this issue is that in TomCat 5.5, the JNDI 
context information is suppose to be located in /META-INF/context.xml. I 
have searched through the archives - found lots of posts with questions 
on this topic, but no answers (can reference all of the articles if needed.)

   It would be good if there was a detailed step-by-step how to for 
setting up a JNDI datasource resource  to support database connection 
pooling for JBuilder 2006, or, if Borland would set up the TomCat 
configuration files using the Tomcat standards (reference 
http://tomcat.apache.org/tomcat-5.0-doc/jndi-resources-howto.html)- this 
way, when users who understand TomCat have an issue, they will no which 
files to look in to troubleshoot - with Jbuilder, its a real mystery 
since within the IDE the TomCat configuration file standards are not 
followed (i.e., placing JNDI context information in /META-INF/context.xml.)

Any help that can be provided is still appreciated, though reference the 
'JNDI Connection Problem Thread' as it contains details for my config.

thanks
Re: Help with JNDI Datasource in JBuilder 2006
#426
Author: Paul Furbacher [TeamB]
Date: Mon, 05 Dec 2005 20:25
73 lines
4324 bytes
Tom wrote:

> No luck still - note I'm working on this issue now as a separate thread 
> 'JNDI Connection Problem Thread' (in this newsgroup), 

Yes, I responded to that before seeing this message.

> however, I wanted 
> to mention that I took a look at the Bookstore code and saw that it does 
> not use JNDI / Connection Pooling:

You are right.  I was looking at it as an example
of how JBuilder writes the context config.  Turns
out, I was confused about that too.  Too much flipping
between different Web apps (TC 4.1.x and TC 5.5.x) in
order to contrast how JBuilder 2006 handles them.


> So this is not a good representative example.  I think one reason why 
> others have stumbled on this issue is that in TomCat 5.5, the JNDI 
> context information is suppose to be located in /META-INF/context.xml. [...]

See my response to your message in the other thread.  As I
mention there, I just re-configured the Spring JPetstore
demo to lookup a JNDI datasource.  I placed the resource def
in <Context> element in the server8080.xml, and referenced
it from the Spring app context xml file.  I edited the
server8080.xml file as described in the archives.  It works.
Spring doesn't choke (to make it choke, I changed the resource
name in the server8080.xml file but didn't in the Spring app
context file so that it wouldn't find the resource in the JNDI
context; it choked alright).

>   It would be good if there was a detailed step-by-step how to for 
> setting up a JNDI datasource resource  to support database connection 
> pooling for JBuilder 2006, or, if Borland would set up the TomCat 
> configuration files using the Tomcat standards (reference 
> http://tomcat.apache.org/tomcat-5.0-doc/jndi-resources-howto.html)- this 
> way, when users who understand TomCat have an issue, they will no which 
> files to look in to troubleshoot - with Jbuilder, its a real mystery 
> since within the IDE the TomCat configuration file standards are not 
> followed (i.e., placing JNDI context information in /META-INF/context.xml.)

I think that the step-by-step how-to exists in the archives.
Perhaps it would be better if there were an article
at BDN about this.  As for TC 5.5. docs, they do state
that it is not prohibited to place resource defs in
the server.xml file.  It's just recommended not to
do that if you want to dynamically reload your context.
For dev purposes within JBuilder, I have found no
need to worry about this.  Rather, for me, the Hot Swap
feature of the debugger is far more important, but again,
if I'm doing refactoring which introduces new methods
in classes which have already been loaded, I have to
restart the server.  So, there's always going to be
a time during development when you've made a significant
change in the Web app and should really just restart it.


-- 


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.
Re: Help with JNDI Datasource in JBuilder 2006
#427
Author: Tom
Date: Wed, 07 Dec 2005 04:09
82 lines
4813 bytes
Paul Furbacher [TeamB] wrote:
> Tom wrote:
> 
>> No luck still - note I'm working on this issue now as a separate 
>> thread 'JNDI Connection Problem Thread' (in this newsgroup), 
> 
> 
> Yes, I responded to that before seeing this message.
> 
>> however, I wanted to mention that I took a look at the Bookstore code 
>> and saw that it does not use JNDI / Connection Pooling:
> 
> 
> You are right.  I was looking at it as an example
> of how JBuilder writes the context config.  Turns
> out, I was confused about that too.  Too much flipping
> between different Web apps (TC 4.1.x and TC 5.5.x) in
> order to contrast how JBuilder 2006 handles them.
> 
> 
>> So this is not a good representative example.  I think one reason why 
>> others have stumbled on this issue is that in TomCat 5.5, the JNDI 
>> context information is suppose to be located in /META-INF/context.xml. 
>> [...]
> 
> 
> See my response to your message in the other thread.  As I
> mention there, I just re-configured the Spring JPetstore
> demo to lookup a JNDI datasource.  I placed the resource def
> in <Context> element in the server8080.xml, and referenced
> it from the Spring app context xml file.  I edited the
> server8080.xml file as described in the archives.  It works.
> Spring doesn't choke (to make it choke, I changed the resource
> name in the server8080.xml file but didn't in the Spring app
> context file so that it wouldn't find the resource in the JNDI
> context; it choked alright).
> 
>>   It would be good if there was a detailed step-by-step how to for 
>> setting up a JNDI datasource resource  to support database connection 
>> pooling for JBuilder 2006, or, if Borland would set up the TomCat 
>> configuration files using the Tomcat standards (reference 
>> http://tomcat.apache.org/tomcat-5.0-doc/jndi-resources-howto.html)- 
>> this way, when users who understand TomCat have an issue, they will no 
>> which files to look in to troubleshoot - with Jbuilder, its a real 
>> mystery since within the IDE the TomCat configuration file standards 
>> are not followed (i.e., placing JNDI context information in 
>> /META-INF/context.xml.)
> 
> 
> I think that the step-by-step how-to exists in the archives.
> Perhaps it would be better if there were an article
> at BDN about this.  As for TC 5.5. docs, they do state
> that it is not prohibited to place resource defs in
> the server.xml file.  It's just recommended not to
> do that if you want to dynamically reload your context.
> For dev purposes within JBuilder, I have found no
> need to worry about this.  Rather, for me, the Hot Swap
> feature of the debugger is far more important, but again,
> if I'm doing refactoring which introduces new methods
> in classes which have already been loaded, I have to
> restart the server.  So, there's always going to be
> a time during development when you've made a significant
> change in the Web app and should really just restart it.
> 
> 
Paul - thanks for all of your help and responses.

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."

This may be the piece I am missing.  What is the name to give the app 
context xml file?  What directory should it be placed in?  and, what are 
the contents that should be placed in this file (if you could show the 
contents of yours as an example that would be great.)

thanks
Tom  cleveland,oh
Re: Help with JNDI Datasource in JBuilder 2006
#428
Author: Tom
Date: Wed, 07 Dec 2005 04:21
81 lines
4771 bytes
Paul Furbacher [TeamB] wrote:
> Tom wrote:
> 
>> No luck still - note I'm working on this issue now as a separate 
>> thread 'JNDI Connection Problem Thread' (in this newsgroup), 
> 
> 
> Yes, I responded to that before seeing this message.
> 
>> however, I wanted to mention that I took a look at the Bookstore code 
>> and saw that it does not use JNDI / Connection Pooling:
> 
> 
> You are right.  I was looking at it as an example
> of how JBuilder writes the context config.  Turns
> out, I was confused about that too.  Too much flipping
> between different Web apps (TC 4.1.x and TC 5.5.x) in
> order to contrast how JBuilder 2006 handles them.
> 
> 
>> So this is not a good representative example.  I think one reason why 
>> others have stumbled on this issue is that in TomCat 5.5, the JNDI 
>> context information is suppose to be located in /META-INF/context.xml. 
>> [...]
> 
> 
> See my response to your message in the other thread.  As I
> mention there, I just re-configured the Spring JPetstore
> demo to lookup a JNDI datasource.  I placed the resource def
> in <Context> element in the server8080.xml, and referenced
> it from the Spring app context xml file.  I edited the
> server8080.xml file as described in the archives.  It works.
> Spring doesn't choke (to make it choke, I changed the resource
> name in the server8080.xml file but didn't in the Spring app
> context file so that it wouldn't find the resource in the JNDI
> context; it choked alright).
> 
>>   It would be good if there was a detailed step-by-step how to for 
>> setting up a JNDI datasource resource  to support database connection 
>> pooling for JBuilder 2006, or, if Borland would set up the TomCat 
>> configuration files using the Tomcat standards (reference 
>> http://tomcat.apache.org/tomcat-5.0-doc/jndi-resources-howto.html)- 
>> this way, when users who understand TomCat have an issue, they will no 
>> which files to look in to troubleshoot - with Jbuilder, its a real 
>> mystery since within the IDE the TomCat configuration file standards 
>> are not followed (i.e., placing JNDI context information in 
>> /META-INF/context.xml.)
> 
> 
> I think that the step-by-step how-to exists in the archives.
> Perhaps it would be better if there were an article
> at BDN about this.  As for TC 5.5. docs, they do state
> that it is not prohibited to place resource defs in
> the server.xml file.  It's just recommended not to
> do that if you want to dynamically reload your context.
> For dev purposes within JBuilder, I have found no
> need to worry about this.  Rather, for me, the Hot Swap
> feature of the debugger is far more important, but again,
> if I'm doing refactoring which introduces new methods
> in classes which have already been loaded, I have to
> restart the server.  So, there's always going to be
> a time during development when you've made a significant
> change in the Web app and should really just restart it.
> 
> 
Paul - thanks for all of your help and responses.

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."

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?

thanks
Tom  cleveland,oh
Re: Help with JNDI Datasource in JBuilder 2006
#429
Author: 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.
Re: Help with JNDI Datasource in JBuilder 2006
#430
Author: willhiker
Date: Thu, 08 Dec 2005 14:05
121 lines
5469 bytes
mybe you can just put  <Resource> to the config/server.xml and add
<resource-ref> to the WEB-INF/web.xml

"Paul Furbacher [TeamB]" <pfurbacher@mac.com>
??????:439696f1@newsgroups.borland.com...
> 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.
Re: Help with JNDI Datasource in JBuilder 2006
#431
Author: Paul Furbacher [TeamB]
Date: Thu, 08 Dec 2005 17:33
37 lines
2551 bytes
willhiker wrote:
> mybe you can just put  <Resource> to the config/server.xml and add
> <resource-ref> to the WEB-INF/web.xml

I believe that's exactly what I wrote if
by "config/server.xml" you mean the server8080.xml
file which JBuilder initially creates and you modify,
and which Tomcat uses when you run your Web app
inside JBuilder.  If you mean the conf/server.xml
file which is in the Tomcat installation in
the "thirdparty" folder, then the answer is absolutely
do NOT do this.  JBuilder manages the Tomcat start
up and specifies its own server8080.xml file; the
one in the distro (in "thirdparty") is never seen.
To prove this, run one of the example Web apps which
ships with JBuilder (in the "samples" folder of the
distro); look in the Message Pane: scroll all the
way to the right and read the end of the first line
in that pane.  You'll see

... -config d:\[pathtoYourProjectsWebapp]\Tomcat\conf\server8080.xml


-- 


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.
Re: Help with JNDI Datasource in JBuilder 2006
#373
Author: Arthur Ore
Date: Wed, 13 Dec 2006 17:24
32 lines
2417 bytes
JBuilder Ent 2006 SP3
I'd been struggling to get the MySQL JDBC driver work inside Tomcat via
JNDI, when I came across this posting and found that I (think I) had done
everything suggested, yet it still didn't work.

I was getting the following error :-
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver
class 'com.mysql.jdbc.Driver'

I could see from the message window that the JDBC library wasn't on the
classpath for Tomcat. When I opted to build a WAR file it seemed to include
the jar file in the right place (WEB_INF/lib).

I may have done something wrong, so sorry if I cause confusion. But in case
others are having problems with this and I haven't made a mistake, here's
what I did to get it working.

Select "Project"|"Project Properties" from the menu. Select run from the
left hand pane and from the right hand pane select the server configuration
used for Tomcat 5.5.9 and click edit.

From the left hand pane find the Library option (the one directly off run).
In the right hand pane select "Use the specified libraries" and make sure
that the MySQL library jar file is present and ONLY any other libraries that
you need Tomcat to access.

Then select run in the left hand pane. In the right hand pane, select
"Server" from the tree structure and to the right make sure the "make
project libraries available on run" is checked.

Click OK twice to close the windows. Now run the project and the path to the
MySQL jar file should no be included in the Tomcat classpath.
Re: Help with JNDI Datasource in JBuilder 2006
#374
Author: Paul Furbacher [TeamB]
Date: Fri, 22 Dec 2006 17:00
43 lines
2703 bytes
I think the following is a good solution to the problem.

(I know that in the past I had done something similar by putting
the JDBC driver jar in the Tomcat "required libraries" tab.)

Arthur Ore wrote:
> [...]
> 
> I may have done something wrong, so sorry if I cause confusion. But in case
> others are having problems with this and I haven't made a mistake, here's
> what I did to get it working.
> 
> Select "Project"|"Project Properties" from the menu. Select run from the
> left hand pane and from the right hand pane select the server configuration
> used for Tomcat 5.5.9 and click edit.
> 
> From the left hand pane find the Library option (the one directly off run).
> In the right hand pane select "Use the specified libraries" and make sure
> that the MySQL library jar file is present and ONLY any other libraries that
> you need Tomcat to access.
> 
> Then select run in the left hand pane. In the right hand pane, select
> "Server" from the tree structure and to the right make sure the "make
> project libraries available on run" is checked.
> 
> Click OK twice to close the windows. Now run the project and the path to the
> MySQL jar file should no be included in the Tomcat classpath.


-- 


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.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads