Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to use a datasource that defined in Tomcat admin console inside a servlet

 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
thank you for reading my post.
I defined a data-source in tomcat administration console.
now i want to use this data source inside my servlet
how i can do that ?
I know some basic like defining the following objects , but i do not know how to initiate initialContext.
which properties we should pass the initialContext constructor ?





Thank you
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is example code in the Tomcat documentation.
In this page, the JNDI data sources were not set up from the admin app but the code to retrieve them will be similar.
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Thank you for reply.
what i have done so far is :
I defined the datasource inside the admin console of tomcat as a global data source.
I foolowed the tutorial and i still get error :
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context

the code that i used it :


i even changed java:comp/env/jdbc/be_Publisher to java:comp/env/jdbc/be_Publisher
but it still return the same problem.

the datasource looks like the following in the server.xml


I should explain that , if i add the datasource to my application context each time that i deploy it into tomcat the application works ok , but as soon as i redeploy it it will loss that datasource configuration.

I tried to add a reference to that datasource in my own web.xml
something like :


but with no luck
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This sounds like more of a problem with Tomcat's Admin App than with servlets in general so, moving to Apache Tomcat.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic