Two Laptop Bag*
The moose likes JBoss/WildFly and the fly likes How to get Connection through JNDI Datasource. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "How to get Connection through JNDI Datasource." Watch "How to get Connection through JNDI Datasource." New topic
Author

How to get Connection through JNDI Datasource.

Shane Connors
Greenhorn

Joined: Oct 29, 2009
Posts: 9
Hi Guys,

here is my datasource file in JBOSS\deploy folder - (flytours-ds.xml)

####my web.xml file######

####jboss-web.xml#####


#### Java class####




When staring the server it throws this exception,


can anyone suggest me a way to get this working?
Shane Connors
Greenhorn

Joined: Oct 29, 2009
Posts: 9
Just to remind im using JBoss4.2 in Windows XP
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10067
    
163

Is that "Java class" a servlet? You can't use the java:comp/env in any Java class. It has to be an enterprise component (like servlet).


[My Blog] [JavaRanch Journal]
Shane Connors
Greenhorn

Joined: Oct 29, 2009
Posts: 9
Jaikiran Pai wrote:Is that "Java class" a servlet? You can't use the java:comp/env in any Java class. It has to be an enterprise component (like servlet).


Hi,

Thats a normal java class, servlet calls this class to get DB connection. wht should i do here?

i have tested this with below coding too
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10067
    
163

Please post the entire exception stacktrace and the relevant code from your servlet which calls this class.
Shane Connors
Greenhorn

Joined: Oct 29, 2009
Posts: 9
Jaikiran Pai wrote:Please post the entire exception stacktrace and the relevant code from your servlet which calls this class.


Complete stack trace is huge, i have copied some part



Servlet

PropertyLoader

Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10067
    
163

Ah, so you are looking it up in a ServletContextListener when the context is initialized. I'm not sure the JNDI java:comp/env is setup correctly at that time.

By the way, why do you want to hold the DB connection in the ServletContextListener?
Shane Connors
Greenhorn

Joined: Oct 29, 2009
Posts: 9
Jaikiran Pai wrote:Ah, so you are looking it up in a ServletContextListener when the context is initialized. I'm not sure the JNDI java:comp/env is setup correctly at that time.

By the way, why do you want to hold the DB connection in the ServletContextListener?


Well...

its working fine with tomcat 6, i wanted to shift this to JBoss 4.2, i couldnt do that because of this issue..
 
Don't get me started about those stupid light bulbs.
 
subject: How to get Connection through JNDI Datasource.