Re: ServletUnit -- How to acquire data sources?
Graeme J Sweeney <[email protected]>
| Newsgroups | gmane.comp.web.httpunit.devel |
|---|---|
| Message-ID | <[email protected]> |
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");
??
--
Graeme -
Outlook Express user? - http://home.in.tum.de/~jain/software/oe-quotefix/
-------------------------------------------------------
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&kid=110944&bid=241720&dat=121642