This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Tomcat and the fly likes how to use  a datasource that defined in Tomcat admin console inside a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "how to use  a datasource that defined in Tomcat admin console inside a servlet" Watch "how to use  a datasource that defined in Tomcat admin console inside a servlet" New topic
Author

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

raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 551
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

Joined: Dec 11, 2004
Posts: 13410

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


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 551
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

Joined: Dec 11, 2004
Posts: 13410

This sounds like more of a problem with Tomcat's Admin App than with servlets in general so, moving to Apache Tomcat.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to use a datasource that defined in Tomcat admin console inside a servlet
 
Similar Threads
How to get a connection from the connection pool in a servlet
Testing private DAO method
[JNDI] Existence or not of attribute
Help: WSAD DataSource Problem
getting javax.naming.NameNotFound Exception.