File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes initialcontext lookup retun null for datasource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "initialcontext lookup retun null for datasource" Watch "initialcontext lookup retun null for datasource" New topic
Author

initialcontext lookup retun null for datasource

Edward Fernando
Greenhorn

Joined: Feb 14, 2012
Posts: 4
right now im trying to connect to db from jsp, and i am using datasource...
first thing i make the Resource in context.xml like this


then i make the jsp like this...just to test the connection....

not getting any name exception then i'm assuming that binding is success....CMIIW

next i'm trying to make a Data source..with code like this....


and here comes the problem....i dont know what is wrong but the datasource alway null....where did it go wrong? please help me....
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Did you mean for the JNDI string "java:comp/env/jdbc/testDB" to match the resource named "jdbc/windoDB"?

I don't see any other possibility, there's only one resource there. You might want to choose a better JNDI string.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

And here's another thing:



Here you have an assignment as your if-expression. That assignment always assigns "true" to the "lookupStat" variable. And then when it's used to control the if-clause, well, it's always true so the code in that block will always be executed. I assume your statement that you weren't getting a name exception is based on the if-clause being executed, rather than actually debugging the code to see whether any exception was thrown?

If you want to compare two values (and you do want that) then use the == operator. The = operator is used for assignments.

And if you want to test a boolean expression to see if it's true, don't use either of those operators. (If you do, it's easy to choose the wrong one accidentally and put a bug into your code.) Here's what your code should be:

Edward Fernando
Greenhorn

Joined: Feb 14, 2012
Posts: 4
Paul Clapham wrote:Did you mean for the JNDI string "java:comp/env/jdbc/testDB" to match the resource named "jdbc/windoDB"?

I don't see any other possibility, there's only one resource there. You might want to choose a better JNDI string.


hmm ok CMIIW....if i not get any "javax.naming.NameNotFoundException"...then there is no problem from the lookup right ? again CMIIW....

Edward Fernando
Greenhorn

Joined: Feb 14, 2012
Posts: 4
now i recreate the context the web.xml and the jsp like this

context.xml


and jsp page


javax.naming.NamingException: Cannot create resource instance........what is wrong now?.....
Maxim Vasilyuk
Greenhorn

Joined: Aug 14, 2013
Posts: 1
Try something, like this (not shure about full lookup path, but works for me):

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: initialcontext lookup retun null for datasource