users@glassfish.java.net

JNDI lookup, dependency injection, datasource

From: <glassfish_at_javadesktop.org>
Date: Mon, 14 Jun 2010 11:52:48 PDT

I'm new to GlassFish and NetBeans and am building a web application. I need to connect to a MySql database via JDBC. I'd like to store the connection information in an XML file so it's available throughout the application. I saw that EE 6 has the ability to inject resources at run-time via dependency injection, however I cannot seem to make this work. I've tried about 1000 various with no luck. That post is here ---> http://stackoverflow.com/questions/3030483/resource-annotation-is-null-at-run-time

I understand there's a second option via JNDI lookups. I would be grateful if someone could show me how this works. Specifically:

Does a <data-source> element go web.xml? Does the code that performs the look have any special requirements or can it be a POJO? A working example would very helpful.


Thank you,
Andrew
[Message sent by forum member 'andrewlaughlin']

http://forums.java.net/jive/thread.jspa?messageID=474230