Adding a datasource to a MemoryContext

12 views
Skip to first unread message

andres

unread,
Feb 19, 2009, 12:30:20 AM2/19/09
to osjava
Hi,

I'm trying to use a very simple shared memory MemoryContext to serve a
single Datasource. Here's what I'm doing:

Hashtable contextEnv=new Hashtable();
contextEnv.put(Context.INITIAL_CONTEXT_FACTORY,
"org.osjava.sj.memory.MemoryContextFactory");
contextEnv.put("jndi.syntax.direction", "left_to_right");
contextEnv.put("jndi.syntax.separator", "/");
contextEnv.put(JndiLoader.SIMPLE_DELIMITER, "/");
JndiLoader loader = new JndiLoader(contextEnv);
InitialContext ic = new InitialContext(contextEnv);

Properties props = new Properties();
props.put("type", "javax.sql.DataSource");
props.put("driver", driver);
props.put("url", url);
props.put("user", user);
props.put("password", pass);

loader.load(props, ic.createSubcontext("jdbc").createSubcontext
("myDS"));

However, I always get a NullPointerException.

Any ideas if what I'm trying to do is even possible?

Thanks a lot,

Andres

Henri Yandell

unread,
Feb 19, 2009, 4:20:32 AM2/19/09
to osj...@googlegroups.com
Agreed on the NPE. It's something to do with the DataSource not liking
being at the top level, even if it's the top level of a context that
is a few levels down.

The following looks like it'll give you the same result but with the
advantage of no NullPointerException :)

Properties props = new Properties();
props.put("jdbc/myDS/type", "javax.sql.DataSource");
props.put("jdbc/myDS/driver", "driverStr");
props.put("jdbc/myDS/url", "urlStr");
props.put("jdbc/myDS/user", "userStr");
props.put("jdbc/myDS/password", "passStr");

loader.load(props, ic);

Hen
Reply all
Reply to author
Forward
0 new messages