Wrox Programmer Forums
|
BOOK: Professional Jakarta Struts
This is the forum to discuss the Wrox book Professional Jakarta Struts by James Goodwill, Richard Hightower; ISBN: 9780764544378
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Jakarta Struts section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 5th, 2003, 04:09 PM
Registered User
 
Join Date: Dec 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default re: getDataSource method


I had a problem compiling the example application in the book.

The method "getDataSource" was not recognized and is not part of the javax.sql.DataSource class. Is there an API I need to download from Jakarta or Sun? I wasn't able to find the method within my libraries.

I was able to successfully cast the Request object into a DataSource object w/out using the getDataSource method, but after compiling the java code, the application doesn't seem to be able to write or read from the database.

Anybody have any ideas?

Thanks
 
Old May 4th, 2004, 11:43 PM
Registered User
 
Join Date: May 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

The "getDataSource" method is only available in the Action class of the struts framework. Please see

http://jakarta.apache.org/struts/api...on/Action.html

for more info. It seems as if getting the DataSource is confined within this particular class. I am trying to get the DataSource within a DAO and Servlet, but to no avail. Perhaps a look at the source for this class might shed some light on how to do this.

For the time being, I suggest adding a <Resource> within the <Context> of the webapp your are using in the /CATALINA_HOME/conf/server.xml, then use:

Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:comp/env");

DataSource ds = (DataSource)envContext.lookup("YOUR_JNDI_DATASOURC E_NAME HERE ");

It worked for me.


 
Old May 10th, 2004, 01:26 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 124
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Has anyone found that this has not worked? Thanks for posting the link, Ivan!

XUMUSKIEFAN
Wrox Moderator
 
Old January 10th, 2005, 01:51 PM
Authorized User
 
Join Date: Oct 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I also needed the datasource in my model class and so passed it as a paramater from the Action class.

I probaly only needed it in my model class because of bad design encapsulation, but adding the following import statment in my model let me get away with it...

import javax.sql.DataSource;





Similar Threads
Thread Thread Starter Forum Replies Last Post
About Method VeradisSanthanam ASP.NET 2.0 Basics 1 June 19th, 2007 06:52 AM
method amit_p_patel VB How-To 2 May 25th, 2007 01:46 AM
Why is this method placed in filip BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 1 August 25th, 2006 09:40 PM
Method StanArtis BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 1 December 6th, 2004 06:09 AM
getdatasource in plugin ashok BOOK: Professional Jakarta Struts 0 July 1st, 2004 03:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.