• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

initialcontext lookup retun null for datasource

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?.....
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try something, like this (not shure about full lookup path, but works for me):

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic