Re: [Httpunit-develop] ServletUnit -- How to ac quire data sources?

Gordon Henriksen <[email protected]>
Newsgroups gmane.comp.web.httpunit.devel
Message-ID <[email protected]>
On Apr 3, 2006, at 07:08, Graeme J Sweeney wrote:

> On Sun, 2 Apr 2006, Gordon Henriksen wrote:
>
>> ServletUnit looks like a useful framework (as long as it's  
>> conforming and un-buggy, anyhow), but I've got one question before  
>> I move ahead. How do I configure ServletUnit to create a JDBC data  
>> source? I'd like the servlet under test to be able to retrieve a  
>> database connection from JNDI much as if it were configured in the  
>> application server.
>
> Don't use ServletUnit but I guess you just configure your own JNDI  
> context and access the DataSource via a lookup?
>
> Properties env = new Properties();
> env.put(Context.INITIAL_CONTEXT_FACTORY,  
> "com.sun.jndi.fscontext.RefFSContextFactory");
> env.put(Context.PROVIDER_URL, "file://<path>/jdbc");
> Context ctx = new InitialContext(env);
> // create a DataSource
> BasicDataSource ds = new BasicDataSource();
> //populate the properties of the datasource e.g.  
> ds.setDriverClassName("org.gjt.mm.mysql.Driver");
> //bind it
> ctx.bind("userCommon", ds);
> //look up
> DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/ 
> userCommon");

Yeah, that's what I was dreading. :) Thanks for the confirmation.

— G


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.